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:
@@ -14,24 +14,24 @@ func (s *Server) handleCallList(c *gin.Context) {
|
||||
|
||||
appName, ok := c.MustGet(api.AppName).(string)
|
||||
if ok && appName == "" {
|
||||
c.JSON(http.StatusBadRequest, models.ErrRoutesValidationMissingAppName)
|
||||
handleErrorResponse(c, models.ErrRoutesValidationMissingAppName)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := s.Datastore.GetApp(c, appName)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, models.ErrAppsNotFound)
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
appRoute, ok := c.MustGet(api.Path).(string)
|
||||
if ok && appRoute == "" {
|
||||
c.JSON(http.StatusBadRequest, models.ErrRoutesValidationMissingPath)
|
||||
handleErrorResponse(c, models.ErrRoutesValidationMissingPath)
|
||||
return
|
||||
}
|
||||
_, err = s.Datastore.GetRoute(c, appName, appRoute)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, models.ErrRoutesNotFound)
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user