@restnfeel/agentc-starter-kit
Version:
한국어 기업용 CMS 모듈 - Task Master AI와 함께 빠르게 웹사이트를 구현할 수 있는 재사용 가능한 컴포넌트 시스템
132 lines (129 loc) • 4.18 kB
JavaScript
import { castToError } from './core.js';
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
class AnthropicError extends Error {
}
class APIError extends AnthropicError {
constructor(status, error, message, headers) {
super(`${APIError.makeMessage(status, error, message)}`);
this.status = status;
this.headers = headers;
this.request_id = headers?.['request-id'];
this.error = error;
}
static makeMessage(status, error, message) {
const msg = error?.message ?
typeof error.message === 'string' ?
error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message;
if (status && msg) {
return `${status} ${msg}`;
}
if (status) {
return `${status} status code (no body)`;
}
if (msg) {
return msg;
}
return '(no status code or body)';
}
static generate(status, errorResponse, message, headers) {
if (!status) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}
const error = errorResponse;
if (status === 400) {
return new BadRequestError(status, error, message, headers);
}
if (status === 401) {
return new AuthenticationError(status, error, message, headers);
}
if (status === 403) {
return new PermissionDeniedError(status, error, message, headers);
}
if (status === 404) {
return new NotFoundError(status, error, message, headers);
}
if (status === 409) {
return new ConflictError(status, error, message, headers);
}
if (status === 422) {
return new UnprocessableEntityError(status, error, message, headers);
}
if (status === 429) {
return new RateLimitError(status, error, message, headers);
}
if (status >= 500) {
return new InternalServerError(status, error, message, headers);
}
return new APIError(status, error, message, headers);
}
}
class APIUserAbortError extends APIError {
constructor({ message } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
this.status = undefined;
}
}
class APIConnectionError extends APIError {
constructor({ message, cause }) {
super(undefined, undefined, message || 'Connection error.', undefined);
this.status = undefined;
// in some environments the 'cause' property is already declared
// @ts-ignore
if (cause)
this.cause = cause;
}
}
class APIConnectionTimeoutError extends APIConnectionError {
constructor({ message } = {}) {
super({ message: message ?? 'Request timed out.' });
}
}
class BadRequestError extends APIError {
constructor() {
super(...arguments);
this.status = 400;
}
}
class AuthenticationError extends APIError {
constructor() {
super(...arguments);
this.status = 401;
}
}
class PermissionDeniedError extends APIError {
constructor() {
super(...arguments);
this.status = 403;
}
}
class NotFoundError extends APIError {
constructor() {
super(...arguments);
this.status = 404;
}
}
class ConflictError extends APIError {
constructor() {
super(...arguments);
this.status = 409;
}
}
class UnprocessableEntityError extends APIError {
constructor() {
super(...arguments);
this.status = 422;
}
}
class RateLimitError extends APIError {
constructor() {
super(...arguments);
this.status = 429;
}
}
class InternalServerError extends APIError {
}
export { APIConnectionError, APIConnectionTimeoutError, APIError, APIUserAbortError, AnthropicError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError };
//# sourceMappingURL=error.js.map