Skip to content

Commit

Permalink
fix(spApi): Compatibility with 429 code
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Nov 29, 2023
1 parent 22d34b7 commit 5919a96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/old-flowers-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

fix(spApi): Compatibility with 429 code
9 changes: 9 additions & 0 deletions packages/js-sdk/src/clients/spclient/spClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
newRequestHeadersByMeta,
} from '@/clients/spclient/auth';
import { parseError } from '@/clients/spclient/spApis/parseError';
import { SP_NOT_AVAILABLE_ERROR_CODE, SP_NOT_AVAILABLE_ERROR_MSG } from '@/constants/http';
import { ReqMeta } from '@/types/auth';
import { injectable } from 'tsyringe';
import { getGetObjectMetaInfo } from './spApis/getObject';
Expand Down Expand Up @@ -80,6 +81,14 @@ export class SpClient implements ISpClient {

const { status } = response;

if (status === SP_NOT_AVAILABLE_ERROR_CODE) {
throw {
code: SP_NOT_AVAILABLE_ERROR_CODE,
message: SP_NOT_AVAILABLE_ERROR_MSG,
statusCode: status,
};
}

if (!response.ok) {
const xmlError = await response.text();
const { code, message } = await parseError(xmlError);
Expand Down
7 changes: 6 additions & 1 deletion packages/js-sdk/src/constants/http.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export const EMPTY_STRING_SHA256 =
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
export const MOCK_SIGNATURE = '1234567812345678123456781234567812345678123456781234567812345678';
export const NORMAL_ERROR_CODE = 404;
export const METHOD_GET = 'GET';
export const METHOD_POST = 'POST';
export const METHOD_PUT = 'PUT';

// SPECIAL ERROR CODE
export const SP_NOT_AVAILABLE_ERROR_CODE = 429;

// SPECIAL ERROR MESSAGE
export const SP_NOT_AVAILABLE_ERROR_MSG = 'SP not available';

0 comments on commit 5919a96

Please sign in to comment.