better error handling

This commit is contained in:
mrjvs
2023-09-14 19:55:50 +02:00
parent 9ff25a4e61
commit 56e84a2a3a
2 changed files with 19 additions and 1 deletions

View File

@@ -6,7 +6,14 @@ export default defineEventHandler(async (event) => {
// parse destination URL
const destination = getQuery<{ destination?: string }>(event).destination;
if (!destination) throw new Error('invalid destination');
if (!destination)
return sendJson({
event,
status: 400,
data: {
error: 'destination query parameter invalid',
},
});
// proxy
await proxyRequest(event, destination, {