feat: add TechLog feature contracts
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { ProblemDetails } from "../../contracts/studio/contract.ts";
|
||||
|
||||
export class StudioGatewayError extends Error {
|
||||
readonly problem: ProblemDetails;
|
||||
readonly status: number;
|
||||
readonly code: ProblemDetails["code"];
|
||||
readonly retryable: boolean;
|
||||
|
||||
constructor(problem: ProblemDetails, options?: ErrorOptions) {
|
||||
super(problem.detail, options);
|
||||
this.name = "StudioGatewayError";
|
||||
this.problem = problem;
|
||||
this.status = problem.status;
|
||||
this.code = problem.code;
|
||||
this.retryable = problem.retryable ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isStudioGatewayError(value: unknown): value is StudioGatewayError {
|
||||
if (typeof value !== "object" || value === null) return false;
|
||||
const candidate = value as Partial<StudioGatewayError>;
|
||||
return (
|
||||
typeof candidate.message === "string" &&
|
||||
typeof candidate.status === "number" &&
|
||||
typeof candidate.code === "string" &&
|
||||
typeof candidate.retryable === "boolean" &&
|
||||
typeof candidate.problem === "object" &&
|
||||
candidate.problem !== null &&
|
||||
candidate.problem.status === candidate.status &&
|
||||
candidate.problem.code === candidate.code
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user