v0.0.594 Add exerr OutputRaw(http.ResponseWriter) method
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m35s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m35s
This commit is contained in:
34
exerr/gin.go
34
exerr/gin.go
@@ -1,9 +1,9 @@
|
||||
package exerr
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
json "git.blackforestbytes.com/BlackForestBytes/goext/gojson"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -68,7 +68,6 @@ func (ee *ExErr) ToDefaultAPIJson() (string, error) {
|
||||
gjr := json.GoJsonRender{Data: ee.ToAPIJson(true, pkgconfig.ExtendedGinOutput, pkgconfig.IncludeMetaInGinOutput), NilSafeSlices: true, NilSafeMaps: true}
|
||||
|
||||
r, err := gjr.RenderString()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -143,3 +142,34 @@ func (ee *ExErr) Output(g *gin.Context) {
|
||||
|
||||
g.Render(statuscode, json.GoJsonRender{Data: ginOutput, NilSafeSlices: true, NilSafeMaps: true})
|
||||
}
|
||||
|
||||
func (ee *ExErr) OutputRaw(w http.ResponseWriter) {
|
||||
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
var statuscode = http.StatusInternalServerError
|
||||
|
||||
var baseCat = ee.RecursiveCategory()
|
||||
var baseType = ee.RecursiveType()
|
||||
var baseStatuscode = ee.RecursiveStatuscode()
|
||||
|
||||
if baseCat == CatUser {
|
||||
statuscode = http.StatusBadRequest
|
||||
} else if baseCat == CatSystem {
|
||||
statuscode = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
if baseStatuscode != nil {
|
||||
statuscode = *ee.StatusCode
|
||||
} else if baseType.DefaultStatusCode != nil {
|
||||
statuscode = *baseType.DefaultStatusCode
|
||||
}
|
||||
|
||||
ginOutput, err := ee.ToDefaultAPIJson()
|
||||
if err != nil {
|
||||
panic(err) // cannot happen
|
||||
}
|
||||
|
||||
w.WriteHeader(statuscode)
|
||||
_, _ = w.Write([]byte(ginOutput))
|
||||
}
|
||||
|
Reference in New Issue
Block a user