Skip to content

Commit

Permalink
refactor: shorter and more readable variable validation
Browse files Browse the repository at this point in the history
  • Loading branch information
miiila committed Sep 26, 2017
1 parent 88ebc7c commit e4e3bf2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function createPagerDutyIncident(options, message, cb) {

return pdApi.send('/incidents', incidentOptions, (err, res, body) => {
let error = err;
if (!error && body !== undefined && body.errors !== undefined && body.errors.length > 0) {
if (!error && body && body.errors && body.errors.length > 0) {
error = new Error(`INCIDENT_CREATION_FAILED Errors: ${JSON.stringify(body.errors)}`);
} else if (!error && res !== undefined && !(res.statusCode === 200 || res.statusCode === 201)) {
} else if (!error && res && !(res.statusCode === 200 || res.statusCode === 201)) {
error = new Error(`INCIDENT_CREATION_FAILED Creating incident failed with status ${res.statusCode}. Returned body: ${JSON.stringify(body)}`);
}
if (error) {
Expand Down

0 comments on commit e4e3bf2

Please sign in to comment.