mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-04 21:42:57 +02:00
errors for go 1.24wq
This commit is contained in:
@@ -37,84 +37,56 @@ func Parse(err string) *Error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// BadRequest generates a 400 error.
|
func newError(id string, code int32, detail string, a ...interface{}) error {
|
||||||
func BadRequest(id, format string, a ...interface{}) error {
|
if len(a) > 0 {
|
||||||
|
detail = fmt.Sprintf(detail, a...)
|
||||||
|
}
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
Id: id,
|
||||||
Code: 400,
|
Code: code,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: detail,
|
||||||
Status: http.StatusText(400),
|
Status: http.StatusText(int(code)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BadRequest generates a 400 error.
|
||||||
|
func BadRequest(id, format string, a ...interface{}) error {
|
||||||
|
return newError(id, 400, format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
// Unauthorized generates a 401 error.
|
// Unauthorized generates a 401 error.
|
||||||
func Unauthorized(id, format string, a ...interface{}) error {
|
func Unauthorized(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 401, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 401,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(401),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forbidden generates a 403 error.
|
// Forbidden generates a 403 error.
|
||||||
func Forbidden(id, format string, a ...interface{}) error {
|
func Forbidden(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 403, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 403,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(403),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotFound generates a 404 error.
|
// NotFound generates a 404 error.
|
||||||
func NotFound(id, format string, a ...interface{}) error {
|
func NotFound(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 404, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 404,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(404),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MethodNotAllowed generates a 405 error.
|
// MethodNotAllowed generates a 405 error.
|
||||||
func MethodNotAllowed(id, format string, a ...interface{}) error {
|
func MethodNotAllowed(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 405, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 405,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(405),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout generates a 408 error.
|
// Timeout generates a 408 error.
|
||||||
func Timeout(id, format string, a ...interface{}) error {
|
func Timeout(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 408, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 408,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(408),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conflict generates a 409 error.
|
// Conflict generates a 409 error.
|
||||||
func Conflict(id, format string, a ...interface{}) error {
|
func Conflict(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 409, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 409,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(409),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalServerError generates a 500 error.
|
// InternalServerError generates a 500 error.
|
||||||
func InternalServerError(id, format string, a ...interface{}) error {
|
func InternalServerError(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return newError(id, 500, format, a...)
|
||||||
Id: id,
|
|
||||||
Code: 500,
|
|
||||||
Detail: fmt.Sprintf(format, a...),
|
|
||||||
Status: http.StatusText(500),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal tries to compare errors.
|
// Equal tries to compare errors.
|
||||||
|
Reference in New Issue
Block a user