-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Response#headers
to errors thrown from the HTTP transport (#3564)
* Add `Response#headers` to errors thrown from the HTTP transport * Do a MINOR patch instead, since this is a new feature
- Loading branch information
1 parent
7eb8c56
commit 5af7f20
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
'@solana/rpc-transport-http': minor | ||
'@solana/errors': minor | ||
--- | ||
|
||
When the HTTP transport throws an error, you can now access the response headers through `e.context.headers`. This can be useful, for instance, if the HTTP error is a 429 Rate Limit error, and the response contains a `Retry-After` header. | ||
|
||
```ts | ||
try { | ||
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send(); | ||
} catch (e) { | ||
if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR)) { | ||
if (e.context.code === 429 /* rate limit error */) { | ||
const retryAfterHeaderValue = e.context.headers.get('Retry-After'); | ||
if (retryAfterHeaderValue != null) { | ||
// ... | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters