36 lines
774 B
Go
36 lines
774 B
Go
package slerrors
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type ErrorResponse struct {
|
|
Code int `json:"errorCode"`
|
|
Message string `json:"errorMessage"`
|
|
}
|
|
|
|
func Respond(c *gin.Context, err error) {
|
|
if IsNotFound(err) {
|
|
c.JSON(http.StatusNotFound, ErrorResponse{
|
|
Code: http.StatusNotFound,
|
|
Message: err.Error(),
|
|
})
|
|
} else if IsForbidden(err) {
|
|
c.JSON(http.StatusForbidden, ErrorResponse{
|
|
Code: http.StatusForbidden,
|
|
Message: err.Error(),
|
|
})
|
|
} else if IsBadRequest(err) {
|
|
c.JSON(http.StatusBadRequest, ErrorResponse{
|
|
Code: http.StatusBadRequest,
|
|
Message: err.Error(),
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusInternalServerError, ErrorResponse{
|
|
Code: http.StatusInternalServerError,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
}
|