fission.Error constructor from http response

This commit is contained in:
Soam Vasani
2016-11-01 18:11:46 -07:00
parent 8b8e8c6539
commit 1cf531038a
+20
View File
@@ -18,6 +18,7 @@ package fission
import (
"fmt"
"net/http"
)
func (e Error) Error() string {
@@ -28,6 +29,25 @@ func MakeError(code int, msg string) Error {
return Error{Code: errorCode(code), Message: msg}
}
func MakeErrorFromHTTP(resp *http.Response) error {
if resp.StatusCode == 200 {
return nil
}
var errCode int
switch resp.StatusCode {
case 403:
errCode = ErrorNotAuthorized
case 404:
errCode = ErrorNotFound
case 400:
errCode = ErrorInvalidArgument
default:
errCode = ErrorInternal
}
return MakeError(errCode, resp.Status)
}
func (err Error) HTTPStatus() int {
var code int
switch err.Code {