From 7faa35e2eedc3469a8ea2133ee6ac6a84aa3b14b Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 20 Sep 2024 14:20:24 +0100 Subject: [PATCH] feat: display error message in response --- server/api/blog.get.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/api/blog.get.ts b/server/api/blog.get.ts index 130053f..7082d5a 100644 --- a/server/api/blog.get.ts +++ b/server/api/blog.get.ts @@ -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