| package apierrors |
|
|
| import ( |
| "net/http" |
|
|
| "github.com/gin-gonic/gin" |
| ) |
|
|
| |
| |
| func JSONError(c *gin.Context, status int, errType, message string, param *string, code interface{}) { |
| errObj := gin.H{ |
| "message": message, |
| "type": errType, |
| "param": param, |
| "code": code, |
| } |
| c.JSON(status, gin.H{"error": errObj}) |
| } |
|
|
| |
| func BadRequest(c *gin.Context, errType, message string, code interface{}) { |
| JSONError(c, http.StatusBadRequest, errType, message, nil, code) |
| } |
|
|
| |
| func InvalidRequest(c *gin.Context, message string, code interface{}) { |
| BadRequest(c, "invalid_request_error", message, code) |
| } |
|
|
| |
| func MissingParam(c *gin.Context, param, code string) { |
| InvalidRequest(c, "Missing required parameter: "+param, code) |
| p := param |
| JSONError(c, http.StatusBadRequest, "invalid_request_error", |
| "Missing required parameter: "+param, &p, code) |
| } |
|
|
| |
| func AuthError(c *gin.Context, status int, message string) { |
| JSONError(c, status, "authorization_error", message, strPtr("Authorization"), status) |
| } |
|
|
| |
| func InternalError(c *gin.Context, errType, message string, code interface{}) { |
| JSONError(c, http.StatusInternalServerError, errType, message, nil, code) |
| } |
|
|
| |
| func NotFoundAccount(c *gin.Context) { |
| c.JSON(http.StatusBadRequest, gin.H{"error": "Not Account Found."}) |
| c.Abort() |
| } |
|
|
| func strPtr(s string) *string { |
| return &s |
| } |
|
|