mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-21 13:23:03 +01:00
This features adds rfc7807 Problem detail responses when an error happens processing a request. This will greatly improve the common issues with "blank pages" and "404 pages" issues which should now properly tell the user what input was wrong (group that does not exist, container name that does not exist, etc.)
19 lines
382 B
Go
19 lines
382 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tniswong/go.rfcx/rfc7807"
|
|
"net/url"
|
|
)
|
|
|
|
func AbortWithProblemDetail(c *gin.Context, p rfc7807.Problem) {
|
|
_ = c.Error(p)
|
|
instance, err := url.Parse(c.Request.RequestURI)
|
|
if err != nil {
|
|
instance = &url.URL{}
|
|
}
|
|
p.Instance = *instance
|
|
c.Header("Content-Type", rfc7807.JSONMediaType)
|
|
c.IndentedJSON(p.Status, p)
|
|
}
|