diff options
Diffstat (limited to 'vendor/github.com/go-openapi/errors/parsing.go')
-rw-r--r-- | vendor/github.com/go-openapi/errors/parsing.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/vendor/github.com/go-openapi/errors/parsing.go b/vendor/github.com/go-openapi/errors/parsing.go index 0f96ce2094..5096e1ea7b 100644 --- a/vendor/github.com/go-openapi/errors/parsing.go +++ b/vendor/github.com/go-openapi/errors/parsing.go @@ -14,7 +14,10 @@ package errors -import "fmt" +import ( + "encoding/json" + "fmt" +) // ParseError represents a parsing error type ParseError struct { @@ -35,6 +38,22 @@ func (e *ParseError) Code() int32 { return e.code } +// MarshalJSON implements the JSON encoding interface +func (e ParseError) MarshalJSON() ([]byte, error) { + var reason string + if e.Reason != nil { + reason = e.Reason.Error() + } + return json.Marshal(map[string]interface{}{ + "code": e.code, + "message": e.message, + "in": e.In, + "name": e.Name, + "value": e.Value, + "reason": reason, + }) +} + const ( parseErrorTemplContent = `parsing %s %s from %q failed, because %s` parseErrorTemplContentNoIn = `parsing %s from %q failed, because %s` |