decentraland / decentraland/builder-client
Add more information when a fetch fails
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
In this block of code https://github.com/decentraland/builder-client/blob/main/src/client/BuilderClient.ts#L102
```
try {
upsertResponse = await this.fetch(`/v1/items/${item.id}`, {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
item: { ...item, eth_address: this.getAddress() }
}),
method: 'put'
})
upsertResponseBody =
(await upsertResponse.json()) as ServerResponse
} catch (error) {
throw new ClientError(error.message, undefined, null)
}
```
If the fetch fails gracefully and there is no body, it's anyway trying to call the .json(). This always force the error to `Unexpected token < in JSON at position 0` and throw away the useful data to know what is happen (for example a Forbidden status code)
Contributor guide
Assessment
This issue has not been assessed yet.