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