backport error changes from ent PR (#12926)

This commit is contained in:
swayne275 2021-10-26 10:11:24 -06:00 committed by GitHub
parent 5dc90d8081
commit 5230d79a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -7,6 +7,10 @@ var (
// No operation is expected to succeed before unsealing
ErrSealed = errors.New("Vault is sealed")
// ErrAPILocked is returned if an operation is performed when the API is
// locked for the request namespace.
ErrAPILocked = errors.New("API access to this namespace has been locked by an administrator")
// ErrStandby is returned if an operation is performed on a standby Vault.
// No operation is expected to succeed until active.
ErrStandby = errors.New("Vault is in standby mode")

View File

@ -51,10 +51,6 @@ var (
// Error indicating that the requested path used to serve a purpose in older
// versions, but the functionality has now been removed
ErrPathFunctionalityRemoved = errors.New("functionality on this path has been removed")
// ErrorLocked indicates that the requested path is locked. Functionality
// will not be restored until it is unlocked.
ErrLocked = errors.New("API access to this namespace has been locked by an administrator")
)
type HTTPCodedError interface {

View File

@ -120,8 +120,6 @@ func RespondErrorCommon(req *Request, resp *Response, err error) (int, error) {
statusCode = http.StatusPreconditionFailed
case errwrap.Contains(err, ErrPathFunctionalityRemoved.Error()):
statusCode = http.StatusNotFound
case errwrap.Contains(err, ErrLocked.Error()):
statusCode = http.StatusLocked
}
}
@ -148,6 +146,10 @@ func AdjustErrorStatusCode(status *int, err error) {
*status = http.StatusServiceUnavailable
}
if errwrap.Contains(err, consts.ErrAPILocked.Error()) {
*status = http.StatusServiceUnavailable
}
// Adjust status code on
if errwrap.Contains(err, "http: request body too large") {
*status = http.StatusRequestEntityTooLarge