mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Remove V1 endpoints and Routes (#1210)
Largely a removal job, however many tests, particularly system level ones relied on Routes. These have been migrated to use Fns. * Add 410 response to swagger * No app names in log tags * Adding constraint in GetCall for FnID * Adding test to check FnID is required on call * Add fn_id to call selector * Fix text in docker mem warning * Correct buildConfig func name * Test fix up * Removing CPU setting from Agent test CPU setting has been deprecated, but the code base is still riddled with it. This just removes it from this layer. Really we need to remove it from Call. * Remove fn id check on calls * Reintroduce fn id required on call * Adding fnID to calls for execute test * Correct setting of app id in middleware * Removes root middlewares ability to redirect fun invocations * Add over sized test check * Removing call fn id check
This commit is contained in:
committed by
Owen Cliffe
parent
6a01dae923
commit
d56a49b321
@@ -16,61 +16,14 @@ import (
|
||||
// ErrInternalServerError returned when something exceptional happens.
|
||||
var ErrInternalServerError = errors.New("internal server error")
|
||||
|
||||
func simpleV1Error(err error) *models.ErrorWrapper {
|
||||
return &models.ErrorWrapper{Error: &models.Error{Message: err.Error()}}
|
||||
}
|
||||
|
||||
func simpleError(err error) *models.Error {
|
||||
return &models.Error{Message: err.Error()}
|
||||
}
|
||||
|
||||
// Legacy this is the old wrapped error
|
||||
// TODO delete me !
|
||||
func handleV1ErrorResponse(ctx *gin.Context, err error) {
|
||||
log := common.Logger(ctx)
|
||||
|
||||
w := ctx.Writer
|
||||
|
||||
if ctx.Err() == context.Canceled {
|
||||
log.Info("client context cancelled")
|
||||
w.WriteHeader(models.ErrClientCancel.Code())
|
||||
return
|
||||
}
|
||||
|
||||
var statuscode int
|
||||
if e, ok := err.(models.APIError); ok {
|
||||
if e.Code() >= 500 {
|
||||
log.WithFields(logrus.Fields{"code": e.Code()}).WithError(e).Error("api error")
|
||||
}
|
||||
if err == models.ErrCallTimeoutServerBusy {
|
||||
// TODO: Determine a better delay value here (perhaps ask Agent). For now 15 secs with
|
||||
// the hopes that fnlb will land this on a better server immediately.
|
||||
w.Header().Set("Retry-After", "15")
|
||||
}
|
||||
statuscode = e.Code()
|
||||
} else {
|
||||
log.WithError(err).WithFields(logrus.Fields{"stack": string(debug.Stack())}).Error("internal server error")
|
||||
statuscode = http.StatusInternalServerError
|
||||
err = ErrInternalServerError
|
||||
}
|
||||
writeV1Error(ctx, w, statuscode, err)
|
||||
}
|
||||
|
||||
func handleErrorResponse(c *gin.Context, err error) {
|
||||
HandleErrorResponse(c.Request.Context(), c.Writer, err)
|
||||
}
|
||||
|
||||
// WriteError easy way to do standard error response, but can set statuscode and error message easier than handleV1ErrorResponse
|
||||
func writeV1Error(ctx context.Context, w http.ResponseWriter, statuscode int, err error) {
|
||||
log := common.Logger(ctx)
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(statuscode)
|
||||
err = json.NewEncoder(w).Encode(simpleV1Error(err))
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("error encoding error json")
|
||||
}
|
||||
}
|
||||
|
||||
// HandleErrorResponse used to handle response errors in the same way.
|
||||
func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error) {
|
||||
log := common.Logger(ctx)
|
||||
|
||||
Reference in New Issue
Block a user