diff --git a/package.json b/package.json index 3052eae27..49b937a57 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api/api.ts b/src/api/api.ts index e13483926..a37c054f8 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -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; } }