This commit is contained in:
@@ -96,9 +96,10 @@ export function startPiggyChatServer(
|
||||
}
|
||||
response.end();
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Piggy chat failed.';
|
||||
const invalidRequest = error instanceof z.ZodError;
|
||||
const message = invalidRequest ? 'Invalid Piggy chat request.' : 'Piggy chat failed.';
|
||||
if (!response.headersSent) {
|
||||
response.writeHead(error instanceof z.ZodError ? 400 : 500, {
|
||||
response.writeHead(invalidRequest ? 400 : 500, {
|
||||
'content-type': 'application/json',
|
||||
});
|
||||
response.end(JSON.stringify({ error: message }));
|
||||
|
||||
Reference in New Issue
Block a user