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:
parent
254fe1556a
commit
1586314e3e
@ -456,10 +456,19 @@ func (b *Builder) Output(ctx context.Context, g *gin.Context) {
|
||||
|
||||
// this is only here to add one level to the trace
|
||||
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
|
||||
b.doOutput(ctx, g)
|
||||
b.doGinOutput(ctx, g)
|
||||
}
|
||||
|
||||
func (b *Builder) doOutput(ctx context.Context, g *gin.Context) {
|
||||
// OutputRaw works teh same as Output() - but does not depend on gin and works with a raw http.ResponseWriter
|
||||
func (b *Builder) OutputRaw(w http.ResponseWriter) {
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
// this is only here to add one level to the trace
|
||||
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
|
||||
b.doRawOutput(w)
|
||||
}
|
||||
|
||||
func (b *Builder) doGinOutput(ctx context.Context, g *gin.Context) {
|
||||
b.errorData.Output(g)
|
||||
|
||||
if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) {
|
||||
@ -471,6 +480,18 @@ func (b *Builder) doOutput(ctx context.Context, g *gin.Context) {
|
||||
b.errorData.CallListener(MethodOutput, ListenerOpt{NoLog: b.noLog})
|
||||
}
|
||||
|
||||
func (b *Builder) doRawOutput(w http.ResponseWriter) {
|
||||
b.errorData.OutputRaw(w)
|
||||
|
||||
if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Error())
|
||||
} else if (b.errorData.Severity == SevWarn) && (pkgconfig.ZeroLogAllGinOutput) {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Warn())
|
||||
}
|
||||
|
||||
b.errorData.CallListener(MethodOutput, ListenerOpt{NoLog: b.noLog})
|
||||
}
|
||||
|
||||
// Print prints the error
|
||||
// If the error is SevErr we also send it to the error-service
|
||||
func (b *Builder) Print(ctxs ...context.Context) Proxy {
|
||||
|
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))
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.593"
|
||||
const GoextVersion = "0.0.594"
|
||||
|
||||
const GoextVersionTimestamp = "2025-07-16T12:50:36+0200"
|
||||
const GoextVersionTimestamp = "2025-07-16T17:13:07+0200"
|
||||
|
Loading…
x
Reference in New Issue
Block a user