v0.0.189
This commit is contained in:
37
exerr/gin.go
37
exerr/gin.go
@@ -1,8 +1,8 @@
|
||||
package exerr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
json "gogs.mikescher.com/BlackForestBytes/goext/gojson"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -34,14 +34,19 @@ func (ee *ExErr) toJson() gin.H {
|
||||
if ee.Timestamp != (time.Time{}) {
|
||||
json["time"] = ee.Timestamp.Format(time.RFC3339)
|
||||
}
|
||||
if ee.WrappedErrType != "" {
|
||||
json["wrappedErrType"] = ee.WrappedErrType
|
||||
}
|
||||
if ee.OriginalError != nil {
|
||||
json["original"] = ee.OriginalError.toJson()
|
||||
}
|
||||
|
||||
pkgconfig.ExtendGinDataOutput(json)
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
func (ee *ExErr) Output(ctx context.Context, g *gin.Context) {
|
||||
func (ee *ExErr) Output(g *gin.Context) {
|
||||
var statuscode = http.StatusInternalServerError
|
||||
|
||||
var baseCat = ee.RecursiveCategory()
|
||||
@@ -62,20 +67,18 @@ func (ee *ExErr) Output(ctx context.Context, g *gin.Context) {
|
||||
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
if pkgconfig.ExtendedGinOutput {
|
||||
g.JSON(statuscode, gin.H{
|
||||
"errorid": ee.UniqueID,
|
||||
"error": ee.RecursiveMessage(),
|
||||
"errorcategory": ee.RecursiveCategory(),
|
||||
"errortype": ee.RecursiveType(),
|
||||
"errodata": ee.toJson(),
|
||||
})
|
||||
} else {
|
||||
g.JSON(statuscode, gin.H{
|
||||
"errorid": ee.UniqueID,
|
||||
"error": ee.RecursiveMessage(),
|
||||
"errorcategory": ee.RecursiveCategory(),
|
||||
"errortype": ee.RecursiveType(),
|
||||
})
|
||||
ginOutput := gin.H{
|
||||
"errorid": ee.UniqueID,
|
||||
"message": ee.RecursiveMessage(),
|
||||
"errorcode": ee.RecursiveType(),
|
||||
"category": ee.RecursiveCategory(),
|
||||
}
|
||||
|
||||
if pkgconfig.ExtendedGinOutput {
|
||||
ginOutput["__data"] = ee.toJson()
|
||||
}
|
||||
|
||||
pkgconfig.ExtendGinOutput(ginOutput)
|
||||
|
||||
g.Render(statuscode, json.GoJsonRender{Data: ginOutput, NilSafeSlices: true, NilSafeMaps: true})
|
||||
}
|
||||
|
Reference in New Issue
Block a user