decentraland / decentraland/builder-client

Add more information when a fetch fails

Open
#30 1 comment 0 reactions 0 assignees View on GitHub
bug
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.