Skip to content

Commit

Permalink
feat: display error message in response
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Sep 20, 2024
1 parent bb8a25b commit 7faa35e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions server/api/blog.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ export default defineCachedEventHandler(async (event) => {
return posts
}
catch (e: any) {
if (e.cause)
// rethrow the original error
throw createError(e.cause)
console.error(e)
// throw a generic error
throw createError({ status: 500, message: 'Failed to fetch posts' })
throw createError({ status: 500, message: `Failed to fetch posts: ${e.message}` })
}
}, { maxAge: 60 * 5 }) // cache API response for 5 minutes

0 comments on commit 7faa35e

Please sign in to comment.