@openfin/cloud-notification-core-api 0.0.1-alpha.f995a04 → 0.0.1-alpha.ff44012
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +10 -9
- package/index.mjs +10 -9
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -108,13 +108,14 @@ function handleAPIException(logger, error, message, exceptionConstructor) {
|
|
|
108
108
|
}
|
|
109
109
|
throw new exceptionConstructor(undefined, undefined, error);
|
|
110
110
|
}
|
|
111
|
-
function checkResponse(logger, response, failMessage, failCode) {
|
|
111
|
+
async function checkResponse(logger, response, failMessage, failCode) {
|
|
112
112
|
if (!response.ok) {
|
|
113
113
|
if (response.status === 401 || response.status === 403) {
|
|
114
114
|
throw new AuthorizationError();
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const responseBody = await response.text();
|
|
117
|
+
logger('error', `Response check failure ${failMessage} - ${response.status}: ${response.statusText} : ${responseBody}`);
|
|
118
|
+
throw new CloudNotificationAPIError(`${failMessage} (HTTP ${response.status}: ${response.statusText})`, failCode, responseBody);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function getRequestHeaders(connectionParameters) {
|
|
@@ -330,7 +331,7 @@ class CloudNotificationAPI {
|
|
|
330
331
|
isFullApi: true,
|
|
331
332
|
}),
|
|
332
333
|
});
|
|
333
|
-
checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
334
|
+
await checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
334
335
|
if (createSessionResponse.status !== 201) {
|
|
335
336
|
throw new CloudNotificationAPIError(`Failed to connect to the Cloud Notification service: ${this.#cloudNotificationSettings.url}`, 'ERR_CONNECT', new Error(createSessionResponse.statusText));
|
|
336
337
|
}
|
|
@@ -374,7 +375,7 @@ class CloudNotificationAPI {
|
|
|
374
375
|
headers: getRequestHeaders(this.#connectionParams),
|
|
375
376
|
body: JSON.stringify(publishPayload),
|
|
376
377
|
});
|
|
377
|
-
checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
378
|
+
await checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
378
379
|
}
|
|
379
380
|
catch (error) {
|
|
380
381
|
handleAPIException(this.#logger, error, 'Error posting notification event', PublishError);
|
|
@@ -410,7 +411,7 @@ class CloudNotificationAPI {
|
|
|
410
411
|
headers: getRequestHeaders(this.#connectionParams),
|
|
411
412
|
body: JSON.stringify(publishPayload),
|
|
412
413
|
});
|
|
413
|
-
checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
414
|
+
await checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
414
415
|
const publishResponseBody = (await publishResponse.json());
|
|
415
416
|
return publishResponseBody;
|
|
416
417
|
}
|
|
@@ -444,7 +445,7 @@ class CloudNotificationAPI {
|
|
|
444
445
|
headers: getRequestHeaders(this.#connectionParams),
|
|
445
446
|
body: JSON.stringify(updatePayload),
|
|
446
447
|
});
|
|
447
|
-
checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
448
|
+
await checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
448
449
|
}
|
|
449
450
|
catch (error) {
|
|
450
451
|
handleAPIException(this.#logger, error, 'Error updating notification', PublishError);
|
|
@@ -467,7 +468,7 @@ class CloudNotificationAPI {
|
|
|
467
468
|
method: 'DELETE',
|
|
468
469
|
headers: getRequestHeaders(this.#connectionParams),
|
|
469
470
|
});
|
|
470
|
-
checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
471
|
+
await checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
471
472
|
}
|
|
472
473
|
catch (error) {
|
|
473
474
|
handleAPIException(this.#logger, error, 'Error deleting notification', PublishError);
|
|
@@ -506,7 +507,7 @@ class CloudNotificationAPI {
|
|
|
506
507
|
sessionId: this.#sessionDetails.sessionId,
|
|
507
508
|
}),
|
|
508
509
|
});
|
|
509
|
-
checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
510
|
+
await checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
510
511
|
const body = (await replayResponse.json());
|
|
511
512
|
return body;
|
|
512
513
|
}
|
package/index.mjs
CHANGED
|
@@ -106,13 +106,14 @@ function handleAPIException(logger, error, message, exceptionConstructor) {
|
|
|
106
106
|
}
|
|
107
107
|
throw new exceptionConstructor(undefined, undefined, error);
|
|
108
108
|
}
|
|
109
|
-
function checkResponse(logger, response, failMessage, failCode) {
|
|
109
|
+
async function checkResponse(logger, response, failMessage, failCode) {
|
|
110
110
|
if (!response.ok) {
|
|
111
111
|
if (response.status === 401 || response.status === 403) {
|
|
112
112
|
throw new AuthorizationError();
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const responseBody = await response.text();
|
|
115
|
+
logger('error', `Response check failure ${failMessage} - ${response.status}: ${response.statusText} : ${responseBody}`);
|
|
116
|
+
throw new CloudNotificationAPIError(`${failMessage} (HTTP ${response.status}: ${response.statusText})`, failCode, responseBody);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
function getRequestHeaders(connectionParameters) {
|
|
@@ -328,7 +329,7 @@ class CloudNotificationAPI {
|
|
|
328
329
|
isFullApi: true,
|
|
329
330
|
}),
|
|
330
331
|
});
|
|
331
|
-
checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
332
|
+
await checkResponse(this.#logger, createSessionResponse, 'Error creating session', 'ERR_CREATE_SESSION');
|
|
332
333
|
if (createSessionResponse.status !== 201) {
|
|
333
334
|
throw new CloudNotificationAPIError(`Failed to connect to the Cloud Notification service: ${this.#cloudNotificationSettings.url}`, 'ERR_CONNECT', new Error(createSessionResponse.statusText));
|
|
334
335
|
}
|
|
@@ -372,7 +373,7 @@ class CloudNotificationAPI {
|
|
|
372
373
|
headers: getRequestHeaders(this.#connectionParams),
|
|
373
374
|
body: JSON.stringify(publishPayload),
|
|
374
375
|
});
|
|
375
|
-
checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
376
|
+
await checkResponse(this.#logger, publishResponse, 'Error posting notification event', 'ERR_POST_NOTIFICATION_EVENT');
|
|
376
377
|
}
|
|
377
378
|
catch (error) {
|
|
378
379
|
handleAPIException(this.#logger, error, 'Error posting notification event', PublishError);
|
|
@@ -408,7 +409,7 @@ class CloudNotificationAPI {
|
|
|
408
409
|
headers: getRequestHeaders(this.#connectionParams),
|
|
409
410
|
body: JSON.stringify(publishPayload),
|
|
410
411
|
});
|
|
411
|
-
checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
412
|
+
await checkResponse(this.#logger, publishResponse, 'Error publishing notification', 'ERR_PUBLISH_NOTIFICATION');
|
|
412
413
|
const publishResponseBody = (await publishResponse.json());
|
|
413
414
|
return publishResponseBody;
|
|
414
415
|
}
|
|
@@ -442,7 +443,7 @@ class CloudNotificationAPI {
|
|
|
442
443
|
headers: getRequestHeaders(this.#connectionParams),
|
|
443
444
|
body: JSON.stringify(updatePayload),
|
|
444
445
|
});
|
|
445
|
-
checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
446
|
+
await checkResponse(this.#logger, updateResponse, 'Error updating notification', 'ERR_UPDATING_NOTIFICATION');
|
|
446
447
|
}
|
|
447
448
|
catch (error) {
|
|
448
449
|
handleAPIException(this.#logger, error, 'Error updating notification', PublishError);
|
|
@@ -465,7 +466,7 @@ class CloudNotificationAPI {
|
|
|
465
466
|
method: 'DELETE',
|
|
466
467
|
headers: getRequestHeaders(this.#connectionParams),
|
|
467
468
|
});
|
|
468
|
-
checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
469
|
+
await checkResponse(this.#logger, deleteResponse, 'Error deleting notification', 'ERR_DELETE_NOTIFICATION');
|
|
469
470
|
}
|
|
470
471
|
catch (error) {
|
|
471
472
|
handleAPIException(this.#logger, error, 'Error deleting notification', PublishError);
|
|
@@ -504,7 +505,7 @@ class CloudNotificationAPI {
|
|
|
504
505
|
sessionId: this.#sessionDetails.sessionId,
|
|
505
506
|
}),
|
|
506
507
|
});
|
|
507
|
-
checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
508
|
+
await checkResponse(this.#logger, replayResponse, 'Error replaying notifications', 'ERR_REPLAY_NOTIFICATIONS');
|
|
508
509
|
const body = (await replayResponse.json());
|
|
509
510
|
return body;
|
|
510
511
|
}
|