From 159fd64fd4330e29a647d001fc95e44474bdda7b Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Mon, 24 Oct 2016 09:50:21 -0700 Subject: [PATCH] Parsing [STATUS] in error messages, to match serverless 1.0 --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c12f6b3ad..5312840f2 100644 --- a/src/index.js +++ b/src/index.js @@ -435,10 +435,17 @@ class Offline { /* RESPONSE SELECTION (among endpoint's possible responses) */ // Failure handling + let errorStatusCode = 0; if (err) { const errorMessage = (err.message || err).toString(); + const re = /\[(\d{3})\]/; + const found = errorMessage.match(re); + if (found && found.length > 1) { + errorStatusCode = found[1]; + } + // Mocks Lambda errors result = { errorMessage, @@ -552,7 +559,7 @@ class Offline { /* HAPIJS RESPONSE CONFIGURATION */ - const statusCode = chosenResponse.statusCode || 200; + const statusCode = errorStatusCode !== 0 ? errorStatusCode : chosenResponse.statusCode || 200; if (!chosenResponse.statusCode) { printBlankLine(); this.serverlessLog(`Warning: No statusCode found for response "${responseName}".`);