Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Unexpected token error #2

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Handling Unexpected token error

  • Loading branch information
Ubuntu
Ubuntu committed Nov 20, 2018
commit ecc9927d919992e2357207fa6da7666e58253ade
@@ -101,14 +101,18 @@ exports.handler = function (event, context) {
};

var req = http.request(options, function (res) {
res.on('data', function (result) {
result = JSON.parse(result.toString());
if (result.response === 'ok') {
context.succeed('all events are sent to Loggly');
} else {
console.log(result.response);
}
});
if (res.statusCode === 200) {

This comment has been minimized.

@kevinegami

kevinegami Nov 30, 2018

Is 200 response and response.ok equivalent? If so, then we only need one of them to run context.succeed?

This comment has been minimized.

@Shwetajain148

Shwetajain148 Nov 30, 2018
Author

@kevinegami, No, they are not same. res.statusCode only returns numeric status code so the first if check is to match the returned HTTP status code and the second if check is to match the returned parsing result in result variable. The result variable has nothing to do with the 200 response.

This comment has been minimized.

@kevinegami

kevinegami Nov 30, 2018

So we can get a 200 status code but response.ok !== True? Seems odd for an API.

This comment has been minimized.

@kevinegami

kevinegami Nov 30, 2018

I understand there is a status code and a response and they are NOT the same, but for a 200 status code shouldn't they be?

res.on('data', function (result) {
result = JSON.parse(result.toString());
if (result.response === 'ok') {
context.succeed('all events are sent to Loggly');
} else {
console.log(result.response);
}
});
} else {
console.log('Error occurred: ' + res.statusCode + ' "' + res.statusMessage + '"');
}
res.on('end', function () {
console.log('No more data in response.');
context.done();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.