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 }));
|
||||
|
||||
@@ -153,10 +153,8 @@ export class PrimeOpenAIChatProvider {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const body = await response.text().catch(() => '');
|
||||
throw new Error(
|
||||
`Piggy inference ${response.status}: ${body.slice(0, 500) || response.statusText}`,
|
||||
);
|
||||
await response.body?.cancel().catch(() => {});
|
||||
throw new Error(`Piggy inference request failed with status ${response.status}.`);
|
||||
}
|
||||
if (!response.body) throw new Error('Piggy inference returned no response stream.');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user