Skip to content

Commit

Permalink
Add error handling to express server functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DemogorGod committed Oct 4, 2023
1 parent 1c3c0b6 commit f41867e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions services/blogs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ app.get('/api/hackmd', async (req, res) => {
requestOptions
)

if (!response.ok) {
console.error(
`Express HackMD API Error Fetching Team Notes: ${response.status} ${response.statusText}`
)
res.status(response.status).send('API Error')
return
}

const data = await response.json()
console.log('data:', data)
// console.log("data:", data);
res.json(data)
})

Expand All @@ -43,8 +51,16 @@ app.get('/api/hackmd/:id', async (req, res) => {
requestOptions
)

if (!response.ok) {
console.error(
`Express HackMD API Error Fetching Team Note: ${response.status} ${response.statusText}`
)
res.status(response.status).send('API Error')
return
}

const data = await response.json()
console.log('data:', data)
// console.log("data:", data);
res.json(data)
})

Expand Down

0 comments on commit f41867e

Please sign in to comment.