You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
774 B

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(),
})
}
}