-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8143a7
commit 7e34fa7
Showing
5 changed files
with
138 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package rest | ||
|
||
import "net/http" | ||
|
||
type RestError struct { | ||
Message string `json:"message"` | ||
Err string `json:"error"` | ||
Code int `json:"code"` | ||
} | ||
|
||
func (r *RestError) Error() string { | ||
return r.Message | ||
} | ||
|
||
func NewBadRequestError(message string) *RestError { | ||
return &RestError{ | ||
Message: message, | ||
Err: "bad_request", | ||
Code: http.StatusBadRequest, | ||
} | ||
} | ||
|
||
func NewUnauthorizedRequestError(message string) *RestError { | ||
return &RestError{ | ||
Message: message, | ||
Err: "unauthorized", | ||
Code: http.StatusUnauthorized, | ||
} | ||
} | ||
|
||
func NewInternalServerError(message string) *RestError { | ||
return &RestError{ | ||
Message: message, | ||
Err: "internal_server_error", | ||
Code: http.StatusInternalServerError, | ||
} | ||
} | ||
|
||
func NewNotFoundError(message string) *RestError { | ||
return &RestError{ | ||
Message: message, | ||
Err: "not_found", | ||
Code: http.StatusNotFound, | ||
} | ||
} | ||
|
||
func NewForbiddenError(message string) *RestError { | ||
return &RestError{ | ||
Message: message, | ||
Err: "forbidden", | ||
Code: http.StatusForbidden, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.