Skip to content

Commit

Permalink
Merge pull request #13 from mazrean/feat/error-unwrapper
Browse files Browse the repository at this point in the history
unwrap echo error
  • Loading branch information
mazrean authored Mar 6, 2024
2 parents f4f314b + 9ba38a9 commit b3a63e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion echo/parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package echoform

import (
"errors"
"io"
"mime"
"net/http"
Expand Down Expand Up @@ -32,6 +33,15 @@ func NewParser(c echo.Context, options ...formstream.ParserOption) (*Parser, err
}, nil
}

// Parse parses the request body.
// It returns the echo.HTTPError if the hook function returns an echo.HTTPError.
func (p *Parser) Parse() error {
return p.Parser.Parse(p.reader)
err := p.Parser.Parse(p.reader)

var httpErr *echo.HTTPError
if errors.As(err, &httpErr) {
return httpErr
}

return err
}
1 change: 1 addition & 0 deletions gin/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewParser(c *gin.Context, options ...formstream.ParserOption) (*Parser, err
}, nil
}

// Parse parses the request body.
func (p *Parser) Parse() error {
return p.Parser.Parse(p.reader)
}

0 comments on commit b3a63e7

Please sign in to comment.