From 9ba38a92ecfe9232493d5d36907f68a83cd448a4 Mon Sep 17 00:00:00 2001 From: mazrean Date: Wed, 6 Mar 2024 20:08:06 +0900 Subject: [PATCH] unwrap echo error --- echo/parser.go | 12 +++++++++++- gin/parser.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/echo/parser.go b/echo/parser.go index 0cdd997..abc02c1 100644 --- a/echo/parser.go +++ b/echo/parser.go @@ -1,6 +1,7 @@ package echoform import ( + "errors" "io" "mime" "net/http" @@ -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 } diff --git a/gin/parser.go b/gin/parser.go index 79f826b..97c4552 100644 --- a/gin/parser.go +++ b/gin/parser.go @@ -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) }