Skip to content

Commit

Permalink
change error handling to create an error object instead of a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Coquand committed Jul 26, 2020
1 parent 1cae7ba commit 46f07b3
Show file tree
Hide file tree
Showing 21 changed files with 13,922 additions and 2,730 deletions.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ we want to create a set decoder, we can use the `map` method.

```typescript
const intSetDecoder: Decoder<Set<number>> = Decoder.array(Decoder.number).map(
numberArray => new Set(numberArray)
(numberArray) => new Set(numberArray)
);
```

Expand All @@ -133,15 +133,8 @@ If there is an error, Decoder will also generate a helpful error report:
jwt: Decoder.string
})
})
> userDecoder.run({wrong: 'hi', auth: {wrongAgain: 'hi'}})
{
type: 'FAIL',
error: 'Error(s) decoding data:\n' +
' Could not decode object:\n' +
' - Key name: Not a string\n' +
' - Key auth: Could not decode object:\n' +
' - Key jwt: Not a string'
}
> JSON.stringify(userDecoder.run({wrong: 'hi', auth: {wrongAgain: 'hi'}}))
'{"type":"FAIL","error":{"name":"Not a string","auth":{"jwt":"Not a string"}}}'
```

This was a brief introduction. From here, please check the API documentation
Expand Down
Loading

0 comments on commit 46f07b3

Please sign in to comment.