mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
fix: add information about target response into error message if inte… (#8281)
# Which Problems Are Solved Execution responses with HTTP StatusCode not equal to 200 interrupt the client request silently. # How the Problems Are Solved Adds information about the recieved StatusCode and Body into the error if StatusCode not 200. # Additional Context Closes #8177 --------- Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -45,3 +45,36 @@ func ZitadelErrorToHTTPStatusCode(err error) (statusCode int, ok bool) {
|
||||
return http.StatusInternalServerError, false
|
||||
}
|
||||
}
|
||||
|
||||
func HTTPStatusCodeToZitadelError(parent error, statusCode int, id string, message string) error {
|
||||
if statusCode == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
var errorFunc func(parent error, id, message string) error
|
||||
switch statusCode {
|
||||
case http.StatusConflict:
|
||||
errorFunc = zerrors.ThrowAlreadyExists
|
||||
case http.StatusGatewayTimeout:
|
||||
errorFunc = zerrors.ThrowDeadlineExceeded
|
||||
case http.StatusInternalServerError:
|
||||
errorFunc = zerrors.ThrowInternal
|
||||
case http.StatusBadRequest:
|
||||
errorFunc = zerrors.ThrowInvalidArgument
|
||||
case http.StatusNotFound:
|
||||
errorFunc = zerrors.ThrowNotFound
|
||||
case http.StatusForbidden:
|
||||
errorFunc = zerrors.ThrowPermissionDenied
|
||||
case http.StatusUnauthorized:
|
||||
errorFunc = zerrors.ThrowUnauthenticated
|
||||
case http.StatusServiceUnavailable:
|
||||
errorFunc = zerrors.ThrowUnavailable
|
||||
case http.StatusNotImplemented:
|
||||
errorFunc = zerrors.ThrowUnimplemented
|
||||
case http.StatusTooManyRequests:
|
||||
errorFunc = zerrors.ThrowResourceExhausted
|
||||
default:
|
||||
errorFunc = zerrors.ThrowUnknown
|
||||
}
|
||||
|
||||
return errorFunc(parent, id, message)
|
||||
}
|
||||
|
Reference in New Issue
Block a user