Skip to content

Commit

Permalink
Fixed breakage when reddit is queried due to invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
omgimanerd committed Oct 2, 2017
1 parent 93c4406 commit 8a66bf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 9 additions & 3 deletions server.js
Expand Up @@ -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)
})
})

Expand All @@ -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)
})
})

Expand Down Expand Up @@ -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)
}
})
})
Expand Down
9 changes: 6 additions & 3 deletions server/api.js
Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 8a66bf3

Please sign in to comment.