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:
Reed Allman
2017-07-13 21:14:01 -07:00
parent db35a8cfd2
commit c0aed2fbb0
27 changed files with 293 additions and 332 deletions

View File

@@ -2,11 +2,10 @@ package server
import (
"context"
"errors"
"net/http"
)
var ErrNoSpecialHandlerFound = errors.New("Path not found")
"gitlab-odx.oracle.com/odx/functions/api/models"
)
type SpecialHandler interface {
Handle(c HandlerContext) error
@@ -56,7 +55,7 @@ func (s *Server) AddSpecialHandler(handler SpecialHandler) {
// UseSpecialHandlers execute all special handlers
func (s *Server) UseSpecialHandlers(ctx context.Context, req *http.Request, resp http.ResponseWriter) (context.Context, error) {
if len(s.specialHandlers) == 0 {
return ctx, ErrNoSpecialHandlerFound
return ctx, models.ErrNoSpecialHandlerFound
}
c := &SpecialHandlerContext{