Skip to content

Commit bbd019d

Browse files
chrustyMarcin Romaszewicz
authored andcommitted
Returning the first line of the error (instead of the 'reason') (oapi-codegen#31)
1 parent eee411e commit bbd019d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

pkg/middleware/oapi_validate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"io/ioutil"
2121
"net/http"
22+
"strings"
2223

2324
"github.com/getkin/kin-openapi/openapi3"
2425
"github.com/getkin/kin-openapi/openapi3filter"
@@ -116,7 +117,10 @@ func ValidateRequestFromContext(ctx echo.Context, router *openapi3filter.Router,
116117
switch e := err.(type) {
117118
case *openapi3filter.RequestError:
118119
// We've got a bad request
119-
return echo.NewHTTPError(http.StatusBadRequest, e.Reason)
120+
// Split up the verbose error by lines and return the first one
121+
// openapi errors seem to be multi-line with a decent message on the first
122+
errorLines := strings.Split(e.Error(), "\n")
123+
return echo.NewHTTPError(http.StatusBadRequest, errorLines[0])
120124
case *openapi3filter.SecurityRequirementsError:
121125
return echo.NewHTTPError(http.StatusForbidden, e.Error())
122126
default:

0 commit comments

Comments
 (0)