Skip to content

Commit

Permalink
Added specific exception for insufficient credit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
verifalia committed May 29, 2020
1 parent f0735e9 commit 0303449
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "verifalia",
"version": "2.4.0",
"version": "2.5.0",
"description": "Verifalia email validation library for Javascript",
"homepage": "https://verifalia.com",
"main": "dist/umd/verifalia.js",
Expand Down
7 changes: 7 additions & 0 deletions src/MultiplexedRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AuthorizationError } from './errors/AuthorizationError';
import { WellKnowMimeContentTypes } from './WellKnowMimeContentTypes';
import { LoggerFactory } from './environments/environment';
import { RequestThrottledError } from './errors/RequestThrottledError';
import { InsufficientCreditError } from './errors/InsufficientCreditError';

const loggerFactory = new LoggerFactory();
const logger = loggerFactory.build('verifalia');
Expand Down Expand Up @@ -92,6 +93,12 @@ export class MultiplexedRestClient {
throw new AuthorizationError(response.statusText);
}

// Payment required

if (response.status === 402) {
throw new InsufficientCreditError();
}

// Throttling

if (response.status === 429) {
Expand Down
11 changes: 11 additions & 0 deletions src/errors/InsufficientCreditError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VerifaliaError } from "./VerifaliaError";

/**
* Thrown when the credit of the requesting account is not enough to accept a given
* email validation job.
*/
export class InsufficientCreditError extends VerifaliaError {
constructor() {
super(`The credit of the requesting account is too low to complete the operation.`);
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export { AuthorizationError } from './errors/AuthorizationError';
export { EndpointServerError } from './errors/EndpointServerError';
export { OperationCancelledError } from './errors/OperationCancelledError';
export { RequestThrottledError } from './errors/RequestThrottledError';
export { ServiceUnreachableError } from './errors/ServiceUnreachableError';
export { ServiceUnreachableError } from './errors/ServiceUnreachableError';
export { InsufficientCreditError } from './errors/InsufficientCreditError';

0 comments on commit 0303449

Please sign in to comment.