Skip to content

Commit

Permalink
throw with error messages or SERVER_ERROR if network response is not ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Dec 15, 2023
1 parent 858cb2b commit ed9b4b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensea-js",
"version": "7.0.1",
"version": "7.0.2",
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
11 changes: 11 additions & 0 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,17 @@ export class OpenSeaAPI {
);

const response = await req.send();
if (!response.ok) {
// If an errors array is returned, throw with the error messages.
const errors = response.bodyJson?.errors;
if (errors?.length > 0) {
throw new Error(`Server Error: ${errors.join(", ")}`);
} else {
// Otherwise, let ethers throw a SERVER_ERROR error since it will include
// more context about the request and response.
response.assertOk();
}
}
return response.bodyJson;
}
}

0 comments on commit ed9b4b2

Please sign in to comment.