Skip to content

Commit

Permalink
- Added error handling in StabilityAIImageInterface.ts to check for H…
Browse files Browse the repository at this point in the history
…TTP 400 Bad Request responses.
  • Loading branch information
TroyceGowdy committed Dec 23, 2024
1 parent da85291 commit 33fcec9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/aux-records/StabilityAIImageInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import axios from 'axios';
import { handleAxiosErrors } from './Utils';
import { traced } from './tracing/TracingDecorators';
import { z } from 'zod';
import { SpanStatusCode, trace } from '@opentelemetry/api';

const TRACE_NAME = 'StabilityAIImageInterface';

Expand Down Expand Up @@ -115,9 +116,26 @@ export class StabilityAIImageInterface implements AIImageInterface {
);

return {
success: true,
images,
};
} catch (err) {
if (axios.isAxiosError(err)) {
if (err.response.status === 400) {
const span = trace.getActiveSpan();
span?.recordException(err);
span?.setStatus({ code: SpanStatusCode.ERROR });

console.error(
`[OpenAIChatInterface] [${request.userId}] [generateImage]: Bad request: ${err.response.data.error.message}`
);
return {
success: false,
errorCode: 'invalid_request',
errorMessage: err.response.data.error.message,
};
}
}
handleAxiosErrors(err);
}
}
Expand Down Expand Up @@ -157,6 +175,7 @@ export class StabilityAIImageInterface implements AIImageInterface {
const data = schema.parse(result.data);

return {
success: true,
images: [
{
base64: data.image,
Expand Down Expand Up @@ -203,6 +222,7 @@ export class StabilityAIImageInterface implements AIImageInterface {
const data = schema.parse(result.data);

return {
success: true,
images: [
{
base64: data.image,
Expand Down Expand Up @@ -252,6 +272,7 @@ export class StabilityAIImageInterface implements AIImageInterface {
const data = schema.parse(result.data);

return {
success: true,
images: [
{
base64: data.image,
Expand Down

0 comments on commit 33fcec9

Please sign in to comment.