Skip to content

Commit 7936ea6

Browse files
authored
Merge pull request #258 from ebpetway/master
Bugfix: Update lambda response processing
2 parents d0dca87 + ee23521 commit 7936ea6

File tree

2 files changed

+63
-54
lines changed

2 files changed

+63
-54
lines changed

index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,10 @@ class ServerlessWSGI {
482482
// remotely, we get a string back and we want it to appear in the console as it would have
483483
// if it was invoked locally.
484484
//
485-
// Thus, console.log is temporarily hijacked to capture the output and parse it as JSON. This
486-
// hack is needed to avoid having to call the provider-specific invoke plugins.
485+
// We capture stdout output in order to parse the array returned from the lambda invocation,
486+
// then restore stdout.
487487
let output = "";
488488

489-
/* eslint-disable no-console */
490-
const native_log = console.log;
491-
console.log = (msg) => (output += msg + "\n");
492489
/* eslint-disable no-unused-vars */
493490
const {
494491
originalStdoutWrite, // Original `write` bound to `process.stdout`#noqa
@@ -500,9 +497,7 @@ class ServerlessWSGI {
500497
orig, // data input
501498
originalStdoutWrite // // Original `write` bound to `process.stdout`
502499
) => {
503-
// Example of filtering ANSI codes for original stdout.write
504-
originalStdoutWrite(orig.replace(/["]+/g, "").replace(/\\n/g, "\n"));
505-
// originalStdoutWrite(orig.substring(orig.indexOf(",") + 7).replace(/\\n/g,"\n") + "\n");
500+
output += orig;
506501
}
507502
);
508503
/* eslint-enable no-unused-vars */
@@ -525,18 +520,18 @@ class ServerlessWSGI {
525520
? _.trimEnd(output[1], "\n")
526521
: output[1];
527522
if (return_code == 0) {
528-
native_log(output_data);
523+
this.serverless.cli.log(output_data);
529524
} else {
530-
return reject(output_data);
525+
return reject(new this.serverless.classes.Error(output_data));
531526
}
532527
} else {
533-
native_log(output);
528+
this.serverless.cli.log(output);
534529
}
535530
return resolve();
536531
})
537532
)
538533
.finally(() => {
539-
console.log = native_log;
534+
restoreStdoutWrite();
540535
});
541536
/* eslint-enable no-console */
542537
}

0 commit comments

Comments
 (0)