Skip to content

Commit

Permalink
Add structured errors to Typescript Client (encoredev#224)
Browse files Browse the repository at this point in the history
This commit adds structured errors to the typescript client in the
form of an `EncoreError` object which will be thrown incase of an
error. This makes a best attempt at recovering the structured error
as reported by an Encore API and parsing it to be easily usable from
withing a client.

This also causes the client to premptively return throw an error if
no bearer token is present when trying to call an Authenticated API.

Fixes encoredev#114

```typescript
const client = new Client(Local)

try {
    const productListing = await client.products.List()
} catch (e: Error) {
    if (isEncoreError(e)) {
        console.log(`Got an ${e.code} error with message ${e.message} and details ${e.details}`)
    } else {
       console.log(`Got error ${e.message}`)
    }
}
```
  • Loading branch information
DomBlack authored May 23, 2022
1 parent 238a47c commit 98cfe24
Show file tree
Hide file tree
Showing 2 changed files with 668 additions and 40 deletions.
Loading

0 comments on commit 98cfe24

Please sign in to comment.