From fbe108a573f292cfa51773862b24d545d209def3 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 14 Jan 2022 11:32:24 +0100 Subject: [PATCH] throw meaningful errors --- packages/health-check/src/utils.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/health-check/src/utils.js b/packages/health-check/src/utils.js index 7e5b09b8..7ff84bec 100644 --- a/packages/health-check/src/utils.js +++ b/packages/health-check/src/utils.js @@ -69,9 +69,15 @@ function getAuthCookie() { // extract set-cookie from successful authentication request const cookies = response.headers["set-cookie"]; + // throw meaningful error when set-cookie header is missing + if (!cookies) throw new Error(`Auth successful (code ${response.statusCode}) but 'set-cookie' header is missing`); + // find the skynet-jwt cookie const jwtcookie = cookies.find((cookie) => cookie.startsWith("skynet-jwt")); + // throw meaningful error when skynet-jwt cookie is missing + if (!jwtcookie) throw new Error(`Header 'set-cookie' found but 'skynet-jwt' cookie is missing`); + // extract just the cookie value (no set-cookie props) from set-cookie return jwtcookie.match(/skynet-jwt=[^;]+;/)[0]; } catch (error) {