Add exports that make controller usable

This commit is contained in:
Soam Vasani
2016-10-29 20:38:50 -07:00
parent ff3efa3434
commit a93c17548c
10 changed files with 107 additions and 93 deletions
+31
View File
@@ -27,3 +27,34 @@ func (e Error) Error() string {
func MakeError(code int, msg string) Error {
return Error{Code: errorCode(code), Message: msg}
}
func (err Error) HTTPStatus() int {
var code int
switch err.Code {
case ErrorNotFound:
code = 404
case ErrorInvalidArgument:
code = 400
case ErrorNoSpace:
code = 500
case ErrorNotAuthorized:
code = 403
default:
code = 500
}
return code
}
func GetHTTPError(err error) (int, string) {
var msg string
var code int
fe, ok := err.(Error)
if ok {
msg = fe.Message
code = fe.HTTPStatus()
} else {
code = 500
msg = err.Error()
}
return code, msg
}