Skip to content

Commit

Permalink
feat: Add docLinks to error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 10, 2024
1 parent e1979ad commit 3970c37
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
7 changes: 7 additions & 0 deletions control-plane/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ app.setErrorHandler((error, request, reply) => {
hdx?.recordException(error);
}

let docsLink;

if ('docsLink' in error) {
docsLink = error.docsLink
}

return reply.status(statusCode).send({
error: {
message: statusCode === 500 ? "Internal server error" : error.message,
docsLink,
},
});
});
Expand Down
89 changes: 43 additions & 46 deletions control-plane/src/utilities/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,97 +33,94 @@ export const isRetryableError = (error: unknown) => {
return false;
};

export class AuthenticationError extends Error {
statusCode = 401;
export class DocumentedError extends Error {
docsLink?: string;

constructor(message: string) {
constructor(message: string, docsLink?: string) {
super(message);
this.name = "DocumentedError";
this.docsLink = docsLink
}
}

export class AuthenticationError extends DocumentedError {
statusCode = 401;

constructor(
message: string,
docsLink: string = "https://docs.inferable.ai/pages/auth"
) {
super(message, docsLink);
this.name = "AuthenticationError";
}
}

export class NotFoundError extends Error {
export class NotFoundError extends DocumentedError {
statusCode: number = 404;

constructor(message: string) {
super(message);
constructor(message: string, docsLink?: string) {
super(message, docsLink);
this.name = "NotFoundError";
}
}

export class BadRequestError extends Error {
export class BadRequestError extends DocumentedError {
statusCode: number = 400;

constructor(message: string) {
super(message);
constructor(message: string, docsLink?: string) {
super(message, docsLink);
this.name = "BadRequestError";
}
}

export class JobPollTimeoutError extends Error {
export class JobPollTimeoutError extends DocumentedError {
statusCode: number = 408;

constructor(message: string) {
super(message);
constructor(message: string, docsLink?: string) {
super(message, docsLink);
this.name = "JobRequestTimeoutError";
}
}

export class InvalidServiceRegistrationError extends Error {
export class InvalidServiceRegistrationError extends DocumentedError {
statusCode = 400;

constructor(message: string) {
super(message);
constructor(
message: string,
docsLink: string = "https://docs.inferable.ai/pages/functions#options"
) {
super(message, docsLink);
this.name = "InvalidServiceRegistrationError";
}
}

export class InvalidJobArgumentsError extends Error {
export class InvalidJobArgumentsError extends DocumentedError {
statusCode = 400;

constructor(message: string) {
super(message);
constructor(
message: string,
docsLink: string = "https://docs.inferable.ai/pages/functions#options"
) {
super(message, docsLink);
this.name = "InvalidArgumentsError";
}
}

export class ContentTooLarge extends Error {
statusCode = 413;

constructor(message: string) {
super(message);
this.name = "ContentTooLarge";
}
}

export class AgentError extends Error {
constructor(message: string) {
super(message);
export class AgentError extends DocumentedError {
constructor(message: string, docsLink?: string) {
super(message, docsLink);
this.name = "AgentError";
}
}

export class JobAuthenticationError extends Error {
constructor(message: string) {
super(message);
this.name = "JobAuthenticationError";
}
}

export class PromptableError extends Error {
constructor(message: string) {
super(message);
this.name = "PromptableError";
}
}

export class RunBusyError extends Error {
export class RunBusyError extends DocumentedError {
statusCode = 409;

constructor(
message: string = "Run is still processing, please try again later.",
docsLink: string = "https://docs.inferable.ai/pages/runs#lifecycle"
) {
super(message);
super(message, docsLink);
this.name = "RunBusyError";
}
}

0 comments on commit 3970c37

Please sign in to comment.