Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d8cf255c80
|
|||
b520282ba0
|
@@ -115,6 +115,9 @@ func (b *bufferedReadCloser) BufferedAll() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := b.Reset(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return b.buffer, nil
|
return b.buffer, nil
|
||||||
|
|
||||||
case modeSourceFinished:
|
case modeSourceFinished:
|
||||||
@@ -131,10 +134,22 @@ func (b *bufferedReadCloser) BufferedAll() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset resets the buffer to the beginning of the buffer.
|
||||||
|
// If the original source is partially read, we will finish reading it and fill our buffer
|
||||||
func (b *bufferedReadCloser) Reset() error {
|
func (b *bufferedReadCloser) Reset() error {
|
||||||
switch b.mode {
|
switch b.mode {
|
||||||
case modeSourceReading:
|
case modeSourceReading:
|
||||||
fallthrough
|
if b.off == 0 {
|
||||||
|
return nil // nobody has read anything yet
|
||||||
|
}
|
||||||
|
err := b.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.mode = modeBufferReading
|
||||||
|
b.off = 0
|
||||||
|
return nil
|
||||||
|
|
||||||
case modeSourceFinished:
|
case modeSourceFinished:
|
||||||
err := b.Close()
|
err := b.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -13,6 +13,25 @@ var reflectTypeStr = reflect.TypeOf("")
|
|||||||
|
|
||||||
func FromError(err error) *ExErr {
|
func FromError(err error) *ExErr {
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
// prevent NPE if we call FromError with err==nil
|
||||||
|
return &ExErr{
|
||||||
|
UniqueID: newID(),
|
||||||
|
Category: CatForeign,
|
||||||
|
Type: TypeInternal,
|
||||||
|
Severity: SevErr,
|
||||||
|
Timestamp: time.Time{},
|
||||||
|
StatusCode: nil,
|
||||||
|
Message: "",
|
||||||
|
WrappedErrType: "nil",
|
||||||
|
WrappedErr: err,
|
||||||
|
Caller: "",
|
||||||
|
OriginalError: nil,
|
||||||
|
Meta: make(MetaMap),
|
||||||
|
Extra: make(map[string]any),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//goland:noinspection GoTypeAssertionOnErrors
|
//goland:noinspection GoTypeAssertionOnErrors
|
||||||
if verr, ok := err.(*ExErr); ok {
|
if verr, ok := err.(*ExErr); ok {
|
||||||
// A simple ExErr
|
// A simple ExErr
|
||||||
|
@@ -100,6 +100,17 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
|||||||
|
|
||||||
if pctx.body != nil {
|
if pctx.body != nil {
|
||||||
if pctx.ginCtx.ContentType() == "application/json" {
|
if pctx.ginCtx.ContentType() == "application/json" {
|
||||||
|
if brc, ok := pctx.body.(dataext.BufferedReadCloser); ok {
|
||||||
|
// Ensures a fully reset (offset=0) buffer before parsing
|
||||||
|
err := brc.Reset()
|
||||||
|
if err != nil {
|
||||||
|
err = exerr.Wrap(err, "Failed to read (brc.reset) json-body").
|
||||||
|
WithType(exerr.TypeBindFailJSON).
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "JSON", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := pctx.ginCtx.ShouldBindJSON(pctx.body); err != nil {
|
if err := pctx.ginCtx.ShouldBindJSON(pctx.body); err != nil {
|
||||||
err = exerr.Wrap(err, "Failed to read json-body").
|
err = exerr.Wrap(err, "Failed to read json-body").
|
||||||
WithType(exerr.TypeBindFailJSON).
|
WithType(exerr.TypeBindFailJSON).
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.544"
|
const GoextVersion = "0.0.546"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-11-26T15:10:27+0100"
|
const GoextVersionTimestamp = "2024-11-28T12:06:57+0100"
|
||||||
|
Reference in New Issue
Block a user