mailgun.js
Advanced tools
Comparing version 3.1.1 to 3.1.2
/*! MIT License © Sindre Sorhus */ | ||
/*! mailgun.js v3.1.1 */ | ||
/*! mailgun.js v3.1.2 */ |
@@ -1,5 +0,4 @@ | ||
import APIErrorOptions from './interfaces/APIErrorOptions'; | ||
export default class APIError extends Error { | ||
export default class APIError extends Error { | ||
status: number | string; | ||
@@ -6,0 +5,0 @@ stack: string; |
@@ -28,2 +28,11 @@ | ||
const streamToString = (stream: any) => { | ||
const chunks: any = [] | ||
return new Promise((resolve, reject) => { | ||
stream.on('data', (chunk: any) => chunks.push(chunk)) | ||
stream.on('error', reject) | ||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))) | ||
}) | ||
} | ||
class Request { | ||
@@ -77,6 +86,10 @@ private username; | ||
if (!response?.ok) { | ||
const message = response?.body && isStream(response.body) | ||
? await streamToString(response.body) | ||
: await response?.json(); | ||
throw new APIError({ | ||
status: response?.status, | ||
statusText: response?.statusText, | ||
body: await response?.json() | ||
body: { message } | ||
} as APIErrorOptions); | ||
@@ -83,0 +96,0 @@ } |
{ | ||
"name": "mailgun.js", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"main": "dist/mailgun.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -44,5 +44,3 @@ const formData = require('form-data'); // importing this way to not have type error in line 13 | ||
it('returns error messages', function () { | ||
api.post('/v3/sandbox.mailgun.org/messages').reply(400, { | ||
message: 'Missing parameter \'to\'.' | ||
}); | ||
api.post('/v3/sandbox.mailgun.org/messages').reply(400, 'Missing parameter \'to\'.'); | ||
@@ -49,0 +47,0 @@ return client.create('sandbox.mailgun.org', { |
@@ -72,3 +72,3 @@ // jscs:disable requireDotNotation | ||
.get('/v2/some/resource') | ||
.reply(429, { message: 'Too many requests' }); | ||
.reply(429, 'Too many requests'); | ||
@@ -75,0 +75,0 @@ const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2203107
3267