anypush
Advanced tools
Comparing version 0.0.1-0 to 0.0.1
@@ -62,10 +62,23 @@ "use strict"; | ||
})); | ||
const status = await new Promise((resolve, reject) => { | ||
request.on('response', response => { | ||
const [status, reason] = await new Promise((resolve, reject) => { | ||
request | ||
.on('response', response => { | ||
var _a; | ||
resolve((_a = response.statusCode) !== null && _a !== void 0 ? _a : 0); | ||
}); | ||
request.on('error', reject); | ||
const status = (_a = response.statusCode) !== null && _a !== void 0 ? _a : 0; | ||
const chunks = []; | ||
response | ||
.on('data', chunk => chunks.push(chunk)) | ||
.on('end', () => { | ||
const content = Buffer.concat(chunks).toString(); | ||
let reason; | ||
if (content.startsWith('{')) { | ||
({ reason } = JSON.parse(content)); | ||
} | ||
resolve([status, reason]); | ||
}) | ||
.on('error', reject); | ||
}) | ||
.on('error', reject); | ||
}); | ||
debug('push response', status, data, message); | ||
debug('push response', { status, reason, data, message }); | ||
switch (status) { | ||
@@ -75,5 +88,5 @@ case 200: | ||
case 400: | ||
throw new Error('Bad request'); | ||
throw new Error(`Bad request: ${reason}`); | ||
case 403: | ||
throw new Error("There was an error with the provider's authentication token"); | ||
throw new Error(`There was an error with the provider's authentication token: ${reason}`); | ||
case 410: | ||
@@ -80,0 +93,0 @@ throw new expected_errors_1.TargetInactiveError('The device token is no longer active for the topic'); |
{ | ||
"name": "anypush", | ||
"version": "0.0.1-0", | ||
"version": "0.0.1", | ||
"description": "AnyPush", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/vilic/anypush.git", |
@@ -368,12 +368,31 @@ import Debug from 'debug'; | ||
const status = await new Promise<number>((resolve, reject) => { | ||
request.on('response', response => { | ||
resolve(response.statusCode ?? 0); | ||
}); | ||
const [status, reason] = await new Promise<[number, string | undefined]>( | ||
(resolve, reject) => { | ||
request | ||
.on('response', response => { | ||
const status = response.statusCode ?? 0; | ||
request.on('error', reject); | ||
}); | ||
const chunks: Buffer[] = []; | ||
debug('push response', status, data, message); | ||
response | ||
.on('data', chunk => chunks.push(chunk)) | ||
.on('end', () => { | ||
const content = Buffer.concat(chunks).toString(); | ||
let reason: string | undefined; | ||
if (content.startsWith('{')) { | ||
({reason} = JSON.parse(content)); | ||
} | ||
resolve([status, reason]); | ||
}) | ||
.on('error', reject); | ||
}) | ||
.on('error', reject); | ||
}, | ||
); | ||
debug('push response', {status, reason, data, message}); | ||
switch (status) { | ||
@@ -383,6 +402,6 @@ case 200: | ||
case 400: | ||
throw new Error('Bad request'); | ||
throw new Error(`Bad request: ${reason}`); | ||
case 403: | ||
throw new Error( | ||
"There was an error with the provider's authentication token", | ||
`There was an error with the provider's authentication token: ${reason}`, | ||
); | ||
@@ -389,0 +408,0 @@ case 410: |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
139579
3229
1