From 39365fd00ee8ef55912dfd038c60da28832bd2b6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 1 Apr 2018 11:23:55 -0600 Subject: [PATCH] Don't crash if widgets are not embeddable --- src/api/dimension/DimensionWidgetService.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/dimension/DimensionWidgetService.ts b/src/api/dimension/DimensionWidgetService.ts index 2876dd2..7b2a340 100644 --- a/src/api/dimension/DimensionWidgetService.ts +++ b/src/api/dimension/DimensionWidgetService.ts @@ -50,11 +50,11 @@ export class DimensionWidgetService { } // Now we need to verify we can actually make the request - await new Promise((resolve, _reject) => { + await new Promise((resolve, reject) => { request(checkUrl, (err, response) => { if (err) { LogService.error("DimensionWidgetService", err); - throw new ApiError(400, "Failed to contact host"); + return reject(new ApiError(400, "Failed to contact host")); } if (response.statusCode >= 200 && response.statusCode < 300) { @@ -62,11 +62,14 @@ export class DimensionWidgetService { const xFrameOptions = (response.headers["x-frame-options"] || '').toLowerCase(); if (xFrameOptions === "sameorigin" || xFrameOptions === "deny") { - throw new ApiError(400, "X-Frame-Options prevents embedding"); + return reject(new ApiError(400, "X-Frame-Options prevents embedding")); } resolve(); - } else throw new ApiError(400, "Non-success status code returned"); + } else { + LogService.verbose("DimensionWidgetService", response.body); + return reject(new ApiError(400, "Non-success status code returned")); + } }); });