Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postmark

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postmark - npm Package Compare versions

Comparing version 2.2.9 to 2.3.0

7

dist/client/BaseClient.js

@@ -13,3 +13,2 @@ "use strict";

var ErrorHandler_1 = require("./ErrorHandler");
var Errors = require("./models/client/Errors");
var packageJson = require("../../package.json");

@@ -23,3 +22,2 @@ var CLIENT_VERSION = packageJson.version;

function BaseClient(token, authHeader, configOptions) {
this.verifyToken(token);
this.clientVersion = CLIENT_VERSION;

@@ -30,2 +28,3 @@ this.token = token.trim();

this.errorHandler = new ErrorHandler_1.ErrorHandler();
this.verifyToken(token);
}

@@ -159,3 +158,3 @@ /**

var scheme = this.clientOptions.useHttps ? "https" : "http";
return scheme + "://" + this.clientOptions.requestHost + "/" + path;
return scheme + "://" + this.clientOptions.requestHost + path;
};

@@ -180,3 +179,3 @@ /**

if (!token || token.trim() === "") {
throw new Errors.PostmarkError("A valid API token must be provided when creating a ClientOptions.");
throw this.errorHandler.generateError(new Error("A valid API token must be provided."));
}

@@ -183,0 +182,0 @@ };

@@ -18,7 +18,7 @@ import * as Errors from "./models/client/Errors";

*
* @param error - error that needs to be identified and transformed to proper Postmark error.
* @param errorMessage - error message that needs to be identified and transformed to proper Postmark error.
*
* @returns properly formatted Postmark error.
*/
private buildError;
private buildGeneralError;
/**

@@ -25,0 +25,0 @@ * Build Postmark error based on HTTP request status.

@@ -19,7 +19,11 @@ "use strict";

ErrorHandler.prototype.generateError = function (error) {
if (error.body !== undefined && error.statusCode !== undefined) {
return this.buildStatusError(error);
if (error.body !== undefined && error.body.Message !== undefined && error.statusCode !== undefined) {
return this.buildStatusError(error.body.Message, error.body.ErrorCode, error.statusCode);
}
else if (error.statusCode !== undefined) {
var errorMessage = (error.message === undefined) ? error.statusMessage : error.message;
return this.buildStatusError(errorMessage, 0, error.statusCode);
}
else {
return this.buildError(error);
return this.buildGeneralError(error.message);
}

@@ -30,8 +34,8 @@ };

*
* @param error - error that needs to be identified and transformed to proper Postmark error.
* @param errorMessage - error message that needs to be identified and transformed to proper Postmark error.
*
* @returns properly formatted Postmark error.
*/
ErrorHandler.prototype.buildError = function (error) {
return new Errors.PostmarkError(error.message);
ErrorHandler.prototype.buildGeneralError = function (errorMessage) {
return new Errors.PostmarkError(errorMessage);
};

@@ -45,14 +49,16 @@ /**

*/
ErrorHandler.prototype.buildStatusError = function (error) {
switch (error.statusCode) {
ErrorHandler.prototype.buildStatusError = function (errorMessage, errorCode, errorStatusCode) {
switch (errorStatusCode) {
case 401:
return new Errors.InvalidAPIKeyError(error.body.Message, error.body.ErrorCode, error.statusCode);
return new Errors.InvalidAPIKeyError(errorMessage, errorCode, errorStatusCode);
case 404:
return new Errors.PostmarkError(errorMessage, errorCode, errorStatusCode);
case 422:
return new Errors.ApiInputError(error.body.Message, error.body.ErrorCode, error.statusCode);
return new Errors.ApiInputError(errorMessage, errorCode, errorStatusCode);
case 500:
return new Errors.InternalServerError(error.body.Message, error.body.ErrorCode, error.statusCode);
return new Errors.InternalServerError(errorMessage, errorCode, errorStatusCode);
case 503:
return new Errors.ServiceUnavailablerError(error.body.Message, error.body.ErrorCode, error.statusCode);
return new Errors.ServiceUnavailablerError(errorMessage, errorCode, errorStatusCode);
default:
return new Errors.UnknownError(error.body.Message, error.body.ErrorCode, error.statusCode);
return new Errors.UnknownError(errorMessage, errorCode, errorStatusCode);
}

@@ -59,0 +65,0 @@ };

@@ -12,3 +12,3 @@ {

],
"version": "2.2.9",
"version": "2.3.0",
"author": "Igor Balos",

@@ -15,0 +15,0 @@ "contributors": [

@@ -62,3 +62,3 @@ import * as postmark from "../../src/index";

expect(() => new postmark.AccountClient(""))
.to.throw("A valid API token must be provided when creating a ClientOptions");
.to.throw("A valid API token must be provided.");
});

@@ -65,0 +65,0 @@

@@ -86,2 +86,16 @@ import { Errors } from "../../src";

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("UnknownError");
expect(postmarkError.message).to.equal(error.message);
});
it("postmark error", () => {
const errorHandler = new ErrorHandler();
const error: any = {
name: "Test name",
message: "test message"
};
const postmarkError = errorHandler.generateError(error);
expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("PostmarkError");

@@ -88,0 +102,0 @@ expect(postmarkError.message).to.equal(error.message);

@@ -96,3 +96,3 @@ import * as postmark from "../../src/index";

expect(() => new postmark.ServerClient(""))
.to.throw("A valid API token must be provided when creating a ClientOptions");
.to.throw("A valid API token must be provided.");
});

@@ -99,0 +99,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc