Implement package limit notification system

This commit is contained in:
Codex Agent
2025-11-01 13:19:07 +01:00
parent 81cdee428e
commit 2c14493604
87 changed files with 4557 additions and 290 deletions

View File

@@ -1,4 +1,5 @@
import { authorizedFetch } from './auth/tokens';
import { ApiError } from './lib/apiError';
import i18n from './i18n';
type JsonValue = Record<string, unknown>;
@@ -331,8 +332,20 @@ type EventSavePayload = {
async function jsonOrThrow<T>(response: Response, message: string): Promise<T> {
if (!response.ok) {
const body = await safeJson(response);
console.error('[API]', message, response.status, body);
throw new Error(message);
const status = response.status;
const errorPayload = body && typeof body === 'object' ? (body as Record<string, unknown>).error : null;
const errorMessage = (errorPayload && typeof errorPayload === 'object' && 'message' in errorPayload && typeof errorPayload.message === 'string')
? errorPayload.message
: message;
const errorCode = errorPayload && typeof errorPayload === 'object' && typeof errorPayload.code === 'string'
? errorPayload.code
: undefined;
const errorMeta = errorPayload && typeof errorPayload === 'object' && typeof errorPayload.meta === 'object'
? errorPayload.meta as Record<string, unknown>
: undefined;
console.error('[API]', errorMessage, status, body);
throw new ApiError(errorMessage, status, errorCode, errorMeta);
}
return (await response.json()) as T;