Permalink
Browse files

Fixed breakage when reddit is queried due to invalid URLs

  • Loading branch information...
omgimanerd committed Oct 2, 2017
1 parent 93c4406 commit 8a66bf3763f47a146dc2867619473f7df3634ed4
Showing with 15 additions and 6 deletions.
  1. +9 −3 server.js
  2. +6 −3 server/api.js
@@ -62,7 +62,9 @@ app.post('/analytics', (request, response) => {
analytics.get(analyticsFile).then(data => {
response.status(201).send(data)
}).catch(error => {
throw error
logError(request)
logError(error)
response.status(500).send(INTERNAL_ERROR.red)
})
})

@@ -74,7 +76,9 @@ app.get('/sources', (request, response) => {
response.status(301).redirect(GITHUB_PAGE)
}
}).catch(error => {
throw error
logError(request)
logError(error)
response.status(500).send(INTERNAL_ERROR.red)
})
})

@@ -102,7 +106,9 @@ app.get('/:source?', (request, response) => {
if (error.data && error.data.code === api.BAD_SOURCE) {
response.status(400).send(formatter.formatHelp(true))
} else {
throw error
logError(request)
logError(error)
response.status(500).send(INTERNAL_ERROR.red)
}
})
})
@@ -76,8 +76,9 @@ const shortenUrl = url => {
// We want to retry the request instantly if it fails.
interval: 0,
timeout: 5000
}).then(data => data.id).catch(error => {
throw new ServerError('Error shortening a URL', error)
}).then(data => data.id).catch(() => {
// Return the original URL on failure.
return url
})
}

@@ -135,8 +136,10 @@ const fetchArticles = source => {
* into a moment object.
*/
return shortenUrl(article.url).then(url => {
article.url = url
article.title = article.title || 'Untitled Article'
article.publishedAt = moment(article.publishedAt)
article.description = article.description || 'No description available'
article.url = url
return article
})
}).then(articles => {

0 comments on commit 8a66bf3

Please sign in to comment.