fix(api): map upstream timeouts to 504 responses
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
||||
} from '../../interfaces/api.ts';
|
||||
import { ClusterCoordinator } from '../../cluster/coordinator.ts';
|
||||
import { ContainerManager } from '../../containers/container-manager.ts';
|
||||
import { UpstreamTimeoutError } from '../../containers/base-container.ts';
|
||||
import { API_SERVER } from '../../constants.ts';
|
||||
import { logger } from '../../logger.ts';
|
||||
import { ModelRegistry } from '../../models/registry.ts';
|
||||
@@ -93,6 +94,11 @@ export class EmbeddingsHandler {
|
||||
});
|
||||
res.end(text);
|
||||
} catch (error) {
|
||||
if (error instanceof UpstreamTimeoutError) {
|
||||
this.sendError(res, 504, error.message, 'upstream_timeout');
|
||||
return;
|
||||
}
|
||||
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
logger.error(`Embeddings error: ${message}`);
|
||||
this.sendError(res, 500, `Embeddings generation failed: ${message}`, 'server_error');
|
||||
@@ -224,6 +230,11 @@ export class EmbeddingsHandler {
|
||||
...init,
|
||||
signal: controller.signal,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
throw new UpstreamTimeoutError();
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user