add new REST errors.

This commit is contained in:
Miroslav Šedivý 2020-10-30 22:06:03 +01:00
parent b6d5df6d04
commit bff779aee7

View File

@ -45,7 +45,16 @@ func ErrInvalidRequest(err error) render.Renderer {
} }
} }
func ErrRender(err error) render.Renderer { func ErrInternalServer(err error) render.Renderer {
return &ErrResponse{
Err: err,
HTTPStatusCode: 500,
StatusText: "Internal server error.",
ErrorText: err.Error(),
}
}
func ErrNot(err error) render.Renderer {
return &ErrResponse{ return &ErrResponse{
Err: err, Err: err,
HTTPStatusCode: 422, HTTPStatusCode: 422,
@ -54,6 +63,16 @@ func ErrRender(err error) render.Renderer {
} }
} }
var ErrNotAuthenticated = &ErrResponse{
HTTPStatusCode: 401,
StatusText: "Invalid or missing access token.",
}
var ErrNotAuthorized = &ErrResponse{
HTTPStatusCode: 403,
StatusText: "Access token does not have the required scope.",
}
var ErrNotFound = &ErrResponse{ var ErrNotFound = &ErrResponse{
HTTPStatusCode: 404, HTTPStatusCode: 404,
StatusText: "Resource not found.", StatusText: "Resource not found.",