Skip to content

Commit

Permalink
docs: changed error handling in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
glebcha committed Mar 11, 2024
1 parent 05dacb9 commit 8acd018
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ api.get('/api/books/12')
.then((jsonFormattedResponse) => {})
.catch(async (pureResponseInstance) => {
const { status, statusText } = pureResponseInstance;
const response = await pureResponseInstance.json();

return { status, statusText };
});
```

### **Basic error handling:**

```javascript
const api = createHttpClient();

api.get('/api/books/12')
.then((jsonFormattedResponse) => {})
.catch(async (pureResponseInstance) => {
const {
status,
statusText,
formattedResponse: response
} = pureResponseInstance;

return { status, statusText, response };
});
Expand All @@ -79,9 +96,8 @@ api.get<Book>('/api/books/12')
.then(({ id, description }) => {})
.catch(async (pureResponseInstance) => {
const { status, statusText } = pureResponseInstance;
const response = await pureResponseInstance.json();

return { status, statusText, response };
return { status, statusText };
});
```

Expand Down

0 comments on commit 8acd018

Please sign in to comment.