parent
cc0221b5ce
commit
66412031fd
@ -1,82 +1,78 @@ |
|||||||
package errors |
package errors |
||||||
|
|
||||||
import ( |
|
||||||
"google.golang.org/grpc/codes" |
|
||||||
) |
|
||||||
|
|
||||||
// BadRequest new BadRequest error that is mapped to a 400 response.
|
// BadRequest new BadRequest error that is mapped to a 400 response.
|
||||||
func BadRequest(domain, reason, message string) *Error { |
func BadRequest(reason, message string) *Error { |
||||||
return Newf(codes.InvalidArgument, domain, reason, message) |
return Newf(400, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsBadRequest determines if err is an error which indicates a BadRequest error.
|
// IsBadRequest determines if err is an error which indicates a BadRequest error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsBadRequest(err error) bool { |
func IsBadRequest(err error) bool { |
||||||
return Code(err) == codes.InvalidArgument |
return Code(err) == 400 |
||||||
} |
} |
||||||
|
|
||||||
// Unauthorized new Unauthorized error that is mapped to a 401 response.
|
// Unauthorized new Unauthorized error that is mapped to a 401 response.
|
||||||
func Unauthorized(domain, reason, message string) *Error { |
func Unauthorized(reason, message string) *Error { |
||||||
return Newf(codes.Unauthenticated, domain, reason, message) |
return Newf(401, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsUnauthorized determines if err is an error which indicates a Unauthorized error.
|
// IsUnauthorized determines if err is an error which indicates a Unauthorized error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsUnauthorized(err error) bool { |
func IsUnauthorized(err error) bool { |
||||||
return Code(err) == codes.Unauthenticated |
return Code(err) == 401 |
||||||
} |
} |
||||||
|
|
||||||
// Forbidden new Forbidden error that is mapped to a 403 response.
|
// Forbidden new Forbidden error that is mapped to a 403 response.
|
||||||
func Forbidden(domain, reason, message string) *Error { |
func Forbidden(reason, message string) *Error { |
||||||
return Newf(codes.PermissionDenied, domain, reason, message) |
return Newf(403, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsForbidden determines if err is an error which indicates a Forbidden error.
|
// IsForbidden determines if err is an error which indicates a Forbidden error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsForbidden(err error) bool { |
func IsForbidden(err error) bool { |
||||||
return Code(err) == codes.PermissionDenied |
return Code(err) == 403 |
||||||
} |
} |
||||||
|
|
||||||
// NotFound new NotFound error that is mapped to a 404 response.
|
// NotFound new NotFound error that is mapped to a 404 response.
|
||||||
func NotFound(domain, reason, message string) *Error { |
func NotFound(reason, message string) *Error { |
||||||
return Newf(codes.NotFound, domain, reason, message) |
return Newf(404, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsNotFound determines if err is an error which indicates an NotFound error.
|
// IsNotFound determines if err is an error which indicates an NotFound error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsNotFound(err error) bool { |
func IsNotFound(err error) bool { |
||||||
return Code(err) == codes.NotFound |
return Code(err) == 404 |
||||||
} |
} |
||||||
|
|
||||||
// Conflict new Conflict error that is mapped to a 409 response.
|
// Conflict new Conflict error that is mapped to a 409 response.
|
||||||
func Conflict(domain, reason, message string) *Error { |
func Conflict(reason, message string) *Error { |
||||||
return Newf(codes.Aborted, domain, reason, message) |
return Newf(409, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsConflict determines if err is an error which indicates a Conflict error.
|
// IsConflict determines if err is an error which indicates a Conflict error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsConflict(err error) bool { |
func IsConflict(err error) bool { |
||||||
return Code(err) == codes.Aborted |
return Code(err) == 409 |
||||||
} |
} |
||||||
|
|
||||||
// InternalServer new InternalServer error that is mapped to a 500 response.
|
// InternalServer new InternalServer error that is mapped to a 500 response.
|
||||||
func InternalServer(domain, reason, message string) *Error { |
func InternalServer(reason, message string) *Error { |
||||||
return Newf(codes.Internal, domain, reason, message) |
return Newf(500, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsInternalServer determines if err is an error which indicates an Internal error.
|
// IsInternalServer determines if err is an error which indicates an Internal error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsInternalServer(err error) bool { |
func IsInternalServer(err error) bool { |
||||||
return Code(err) == codes.Internal |
return Code(err) == 500 |
||||||
} |
} |
||||||
|
|
||||||
// ServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.
|
// ServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.
|
||||||
func ServiceUnavailable(domain, reason, message string) *Error { |
func ServiceUnavailable(reason, message string) *Error { |
||||||
return Newf(codes.Unavailable, domain, reason, message) |
return Newf(503, reason, message) |
||||||
} |
} |
||||||
|
|
||||||
// IsServiceUnavailable determines if err is an error which indicates a Unavailable error.
|
// IsServiceUnavailable determines if err is an error which indicates a Unavailable error.
|
||||||
// It supports wrapped errors.
|
// It supports wrapped errors.
|
||||||
func IsServiceUnavailable(err error) bool { |
func IsServiceUnavailable(err error) bool { |
||||||
return Code(err) == codes.Unavailable |
return Code(err) == 503 |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue