Handles HTTP requests with authentication, error parsing, and retry logic for robust API communication.
// Source: https://github.com/agentscope-ai/QwenPaw | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { getApiUrl, clearAuthToken } from "./config";
import { buildAuthHeaders } from "./authHeaders";
import { getLoginHref, isLoginPath } from "../utils/navigationMode";
export class ApiError extends Error {
readonly status: number;
constructor(status: number, message: string) {
super(message);
this.status = status;
this.name = "ApiError";
}
}
function getErrorMessageFromBody(
text: string,
contentType: string,
): string | null {
if (!text) {
return null;
}
if (!contentType.includes("application/json")) {
return text;
}
try {
const
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key