mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
mask errors in api response, log real error
we had this _almost_ right, in that we were trying, but we weren't masking the error from the user response for any error we don't intend to show. this also adds a stack trace from any internal server errors, so that we might be able to track them down in the future (looking at you, 'context deadline exceeded'). in addition, this adds a new `models.APIError` interface which all of the errors in `models` now implement, and can be caught easily / added to easily. the front end now does no status rewriting based on api errors, now when we get a non-nil error we can call `handleResponse(c, err)` with it and if it's a proper error, return it to the user with the right status code, otherwise log a stack trace and return `internal server error`. this cleans up a lot of the front end code. also rewrites start task ctx deadline exceeded as timeout. with iw we had async tasks so we could start the clock later and it didn't matter, but now with sync tasks time out sometimes just making docker calls, and we want the task status to show up as timed out. we may want to just catch all this above in addition to this, but this seems like the right thing to do. remove squishing together errors. this was weird, now we return the first error for the purposes of using the new err interface. removed a lot of 5xx errors that really should have been 4xx errors. changed some of the 400 errors to 409 errors, since they are from sending in conflicting info and not a malformed request. removed unused errors / useless errors (many were used for logging, and didn't provide any context. now with stack traces we don't need context as much in the logs).
This commit is contained in:
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
@@ -47,8 +46,7 @@ type Datastore interface {
|
||||
|
||||
// InsertRoute inserts a route. Returns ErrDatastoreEmptyRoute when route is nil, and ErrDatastoreEmptyAppName
|
||||
// or ErrDatastoreEmptyRoutePath for empty AppName or Path.
|
||||
// Returns ErrRoutesAlreadyExists if the exact route.Path already exists, or ErrRoutesCreate if a conflicting
|
||||
// route already exists.
|
||||
// Returns ErrRoutesAlreadyExists if the exact route.Path already exists
|
||||
InsertRoute(ctx context.Context, route *Route) (*Route, error)
|
||||
|
||||
// UpdateRoute updates route's Config and Header fields. Returns ErrDatastoreEmptyRoute when route is nil, and
|
||||
@@ -70,12 +68,3 @@ type Datastore interface {
|
||||
// GetDatabase returns the underlying sqlx database implementation
|
||||
GetDatabase() *sqlx.DB
|
||||
}
|
||||
|
||||
var (
|
||||
ErrDatastoreEmptyAppName = errors.New("Missing app name")
|
||||
ErrDatastoreEmptyRoutePath = errors.New("Missing route name")
|
||||
ErrDatastoreEmptyApp = errors.New("Missing app")
|
||||
ErrDatastoreEmptyRoute = errors.New("Missing route")
|
||||
ErrDatastoreEmptyKey = errors.New("Missing key")
|
||||
ErrDatastoreEmptyTaskID = errors.New("Missing task ID")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user