Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
philbot9 committed Oct 26, 2017
1 parent 2019e3e commit 30f56b4
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 246 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"httpdispatcher": "^0.4.0",
"jade": "^1.9.2",
"lodash": "^3.10.1",
"mime": "^1.4.1",
"moment": "^2.10.6",
"mongo-sanitize": "^1.0.0",
"nodemailer": "^2.1.0",
Expand Down
15 changes: 8 additions & 7 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ module.exports = function (req, res) {
}

if (!requestBody) {
return respond(400, {error: 'Received an empty request'})
return respond(400, { error: 'Received an empty request' })
}

var videoID = requestBody.videoID
if (!videoID) {
return respond(400, {error: "Missing field 'videoID'"})
return respond(400, { error: "Missing field 'videoID'" })
}

var pageToken = requestBody.pageToken || null

fetchCommentPage(videoID, pageToken)
.then(function (page) {
if (!page) {
respond(500, {error: 'Internal server error'})
respond(500, { error: 'Internal server error' })
throw new Error('Did not receive a comment page')
}
respond(200, page)
}).catch(function (error) {
console.error(error)
respond(500, {error: 'Fetching comment page failed.'})
})
})
.catch(function (error) {
console.error(error)
respond(500, error)
})

function respond (statusCode, result) {
res.writeHead(statusCode, {
Expand Down
Loading

0 comments on commit 30f56b4

Please sign in to comment.