Revert "Upgrade linter and formatter to Ultracite" (#1226)

This commit is contained in:
josh 2025-09-21 12:03:29 +01:00 committed by GitHub
parent 0e320b391d
commit 1aff7d9868
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 8334 additions and 6943 deletions

View file

@ -1,49 +1,49 @@
export type ErrorType =
| "bad_request"
| "unauthorized"
| "forbidden"
| "not_found"
| "rate_limit"
| "offline";
| 'bad_request'
| 'unauthorized'
| 'forbidden'
| 'not_found'
| 'rate_limit'
| 'offline';
export type Surface =
| "chat"
| "auth"
| "api"
| "stream"
| "database"
| "history"
| "vote"
| "document"
| "suggestions"
| "activate_gateway";
| 'chat'
| 'auth'
| 'api'
| 'stream'
| 'database'
| 'history'
| 'vote'
| 'document'
| 'suggestions'
| 'activate_gateway';
export type ErrorCode = `${ErrorType}:${Surface}`;
export type ErrorVisibility = "response" | "log" | "none";
export type ErrorVisibility = 'response' | 'log' | 'none';
export const visibilityBySurface: Record<Surface, ErrorVisibility> = {
database: "log",
chat: "response",
auth: "response",
stream: "response",
api: "response",
history: "response",
vote: "response",
document: "response",
suggestions: "response",
activate_gateway: "response",
database: 'log',
chat: 'response',
auth: 'response',
stream: 'response',
api: 'response',
history: 'response',
vote: 'response',
document: 'response',
suggestions: 'response',
activate_gateway: 'response',
};
export class ChatSDKError extends Error {
type: ErrorType;
surface: Surface;
statusCode: number;
public type: ErrorType;
public surface: Surface;
public statusCode: number;
constructor(errorCode: ErrorCode, cause?: string) {
super();
const [type, surface] = errorCode.split(":");
const [type, surface] = errorCode.split(':');
this.type = type as ErrorType;
this.cause = cause;
@ -52,13 +52,13 @@ export class ChatSDKError extends Error {
this.statusCode = getStatusCodeByType(this.type);
}
toResponse() {
public toResponse() {
const code: ErrorCode = `${this.type}:${this.surface}`;
const visibility = visibilityBySurface[this.surface];
const { message, cause, statusCode } = this;
if (visibility === "log") {
if (visibility === 'log') {
console.error({
code,
message,
@ -66,8 +66,8 @@ export class ChatSDKError extends Error {
});
return Response.json(
{ code: "", message: "Something went wrong. Please try again later." },
{ status: statusCode }
{ code: '', message: 'Something went wrong. Please try again later.' },
{ status: statusCode },
);
}
@ -76,60 +76,60 @@ export class ChatSDKError extends Error {
}
export function getMessageByErrorCode(errorCode: ErrorCode): string {
if (errorCode.includes("database")) {
return "An error occurred while executing a database query.";
if (errorCode.includes('database')) {
return 'An error occurred while executing a database query.';
}
switch (errorCode) {
case "bad_request:api":
case 'bad_request:api':
return "The request couldn't be processed. Please check your input and try again.";
case "bad_request:activate_gateway":
return "AI Gateway requires a valid credit card on file to service requests. Please visit https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dadd-credit-card to add a card and unlock your free credits.";
case 'bad_request:activate_gateway':
return 'AI Gateway requires a valid credit card on file to service requests. Please visit https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dadd-credit-card to add a card and unlock your free credits.';
case "unauthorized:auth":
return "You need to sign in before continuing.";
case "forbidden:auth":
return "Your account does not have access to this feature.";
case 'unauthorized:auth':
return 'You need to sign in before continuing.';
case 'forbidden:auth':
return 'Your account does not have access to this feature.';
case "rate_limit:chat":
return "You have exceeded your maximum number of messages for the day. Please try again later.";
case "not_found:chat":
return "The requested chat was not found. Please check the chat ID and try again.";
case "forbidden:chat":
return "This chat belongs to another user. Please check the chat ID and try again.";
case "unauthorized:chat":
return "You need to sign in to view this chat. Please sign in and try again.";
case "offline:chat":
case 'rate_limit:chat':
return 'You have exceeded your maximum number of messages for the day. Please try again later.';
case 'not_found:chat':
return 'The requested chat was not found. Please check the chat ID and try again.';
case 'forbidden:chat':
return 'This chat belongs to another user. Please check the chat ID and try again.';
case 'unauthorized:chat':
return 'You need to sign in to view this chat. Please sign in and try again.';
case 'offline:chat':
return "We're having trouble sending your message. Please check your internet connection and try again.";
case "not_found:document":
return "The requested document was not found. Please check the document ID and try again.";
case "forbidden:document":
return "This document belongs to another user. Please check the document ID and try again.";
case "unauthorized:document":
return "You need to sign in to view this document. Please sign in and try again.";
case "bad_request:document":
return "The request to create or update the document was invalid. Please check your input and try again.";
case 'not_found:document':
return 'The requested document was not found. Please check the document ID and try again.';
case 'forbidden:document':
return 'This document belongs to another user. Please check the document ID and try again.';
case 'unauthorized:document':
return 'You need to sign in to view this document. Please sign in and try again.';
case 'bad_request:document':
return 'The request to create or update the document was invalid. Please check your input and try again.';
default:
return "Something went wrong. Please try again later.";
return 'Something went wrong. Please try again later.';
}
}
function getStatusCodeByType(type: ErrorType) {
switch (type) {
case "bad_request":
case 'bad_request':
return 400;
case "unauthorized":
case 'unauthorized':
return 401;
case "forbidden":
case 'forbidden':
return 403;
case "not_found":
case 'not_found':
return 404;
case "rate_limit":
case 'rate_limit':
return 429;
case "offline":
case 'offline':
return 503;
default:
return 500;