Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/bitcore-wallet-client/src/lib/errors/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ export const errorSpec: IErrorSpec[] = [
name: 'PAYLOAD_TOO_LARGE',
message: 'The request payload is too large.'
},
{
name: 'TOO_MANY_REQUESTS_ERROR',
message: 'Too many requests. Please try again later.'
},
{
name: 'BAD_GATEWAY_ERROR',
message: 'Wallet service is temporarily unavailable. Please try again later.'
},
{
name: 'GATEWAY_TIMEOUT_ERROR',
message: 'Wallet service took too long to respond. Please try again.'
},
{
name: 'INTERNAL_SERVER_ERROR',
message: 'Wallet service error. Please try again later or contact support if the problem persists.'
},
{
name: 'UPGRADE_NEEDED',
message: 'Please update your client.'
Expand Down
15 changes: 14 additions & 1 deletion packages/bitcore-wallet-client/src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,25 @@ export class Request<CredT = Credentials> {
if (res.status === 503) return reject(new Errors.MAINTENANCE_ERROR());
if (res.status === 404) return reject(new Errors.NOT_FOUND());
if (res.status === 413) return reject(new Errors.PAYLOAD_TOO_LARGE());
if (res.status === 429) return reject(new Errors.TOO_MANY_REQUESTS_ERROR());
if (res.status === 502) return reject(new Errors.BAD_GATEWAY_ERROR());
if (res.status === 504) return reject(new Errors.GATEWAY_TIMEOUT_ERROR());
if (!res.status) return reject(new Errors.CONNECTION_ERROR());

log.error('HTTP Error:' + res.status);

if (!res.body || !Object.keys(res.body).length)
if (
res.status === 500 &&
(!res.body ||
typeof res.body !== 'object' ||
!Object.keys(res.body).length)
) {
return reject(new Errors.INTERNAL_SERVER_ERROR());
}

if (!res.body || !Object.keys(res.body).length) {
return reject(new Error(res.status + `${err?.message ? ': ' + err.message : ''}`));
}
return reject(Request._parseError(res.body));
}

Expand Down
Loading