From 859b9e778681f35ab22203970232b77a10367a92 Mon Sep 17 00:00:00 2001 From: Metauro <278206624@qq.com> Date: Mon, 6 Jul 2020 14:14:59 -0500 Subject: [PATCH] feat(errors): add gateway, service error (#1797) --- errors/errors.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/errors/errors.go b/errors/errors.go index 70ffca9a..a4fc9a5e 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -116,6 +116,46 @@ func InternalServerError(id, format string, a ...interface{}) error { } } +// NotImplemented generates a 501 error +func NotImplemented(id, format string, a ...interface{}) error { + return &Error{ + Id: id, + Code: 501, + Detail: fmt.Sprintf(format, a...), + Status: http.StatusText(501), + } +} + +// BadGateway generates a 502 error +func BadGateway(id, format string, a ...interface{}) error { + return &Error{ + Id: id, + Code: 502, + Detail: fmt.Sprintf(format, a...), + Status: http.StatusText(502), + } +} + +// ServiceUnavailable generates a 503 error +func ServiceUnavailable(id, format string, a ...interface{}) error { + return &Error{ + Id: id, + Code: 503, + Detail: fmt.Sprintf(format, a...), + Status: http.StatusText(503), + } +} + +// GatewayTimeout generates a 504 error +func GatewayTimeout(id, format string, a ...interface{}) error { + return &Error{ + Id: id, + Code: 504, + Detail: fmt.Sprintf(format, a...), + Status: http.StatusText(504), + } +} + // Equal tries to compare errors func Equal(err1 error, err2 error) bool { verr1, ok1 := err1.(*Error)