Skip to content

Commit

Permalink
Validate results.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed May 11, 2023
1 parent de33da0 commit 9c86a55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ The format is based on [Keep a Changelog], and this project adheres to
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [0.10.1] - 2023-05-11

### Fixed

- `Router` now calls `Validate()` on call results

## [0.10.0] - 2023-05-11

### Changed
Expand Down
9 changes: 9 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func NewSuccessResponse(requestID json.RawMessage, result any) Response {
}

if result != nil {
if result, ok := result.(Validatable); ok {
if err := result.Validate(); err != nil {
return NewErrorResponse(
requestID,
fmt.Errorf("result is invalid: %w", err),
)
}
}

var err error
res.Result, err = json.Marshal(result)
if err != nil {
Expand Down

0 comments on commit 9c86a55

Please sign in to comment.