Skip to content

Commit

Permalink
Parsing [STATUS] in error messages, to match serverless 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Oct 24, 2016
1 parent ca243e6 commit 159fd64
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}".`);
Expand Down

0 comments on commit 159fd64

Please sign in to comment.