mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-24 22:39:25 +01:00
37 lines
844 B
Go
37 lines
844 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type ProblemDetail struct {
|
|
// Type is a unique error code
|
|
Type string `json:"type,omitempty"`
|
|
// Status is the HTTP Status code
|
|
Status int `json:"status,omitempty"`
|
|
// Title is a human-readable error message
|
|
Title string `json:"title,omitempty"`
|
|
// Detail is a human-readable error description
|
|
Detail string `json:"detail,omitempty"`
|
|
//
|
|
Instance string
|
|
error error
|
|
}
|
|
|
|
func ValidationError(err error) ProblemDetail {
|
|
return ProblemDetail{
|
|
Type: "validation-error",
|
|
Status: http.StatusBadRequest,
|
|
Title: "Bad Request",
|
|
Detail: err.Error(),
|
|
Instance: "https://sablierapp.dev/#/errors?id=validation-error",
|
|
error: err,
|
|
}
|
|
}
|
|
|
|
func AbortWithProblemDetail(c *gin.Context, p ProblemDetail) {
|
|
_ = c.Error(p.error)
|
|
c.IndentedJSON(p.Status, p)
|
|
}
|