mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-07 20:47:49 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/*
|
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
*/
|
|
|
|
import { PlexAPIError } from "./plexapierror.js";
|
|
|
|
/** The fallback error class if no more specific error class is matched */
|
|
export class SDKError extends PlexAPIError {
|
|
constructor(
|
|
message: string,
|
|
httpMeta: {
|
|
response: Response;
|
|
request: Request;
|
|
body: string;
|
|
},
|
|
) {
|
|
if (message) {
|
|
message += `: `;
|
|
}
|
|
message += `Status ${httpMeta.response.status}`;
|
|
const contentType = httpMeta.response.headers.get("content-type") || `""`;
|
|
if (contentType !== "application/json") {
|
|
message += ` Content-Type ${
|
|
contentType.includes(" ") ? `"${contentType}"` : contentType
|
|
}`;
|
|
}
|
|
const body = httpMeta.body || `""`;
|
|
message += body.length > 100 ? "\n" : ". ";
|
|
let bodyDisplay = body;
|
|
if (body.length > 10000) {
|
|
const truncated = body.substring(0, 10000);
|
|
const remaining = body.length - 10000;
|
|
bodyDisplay = `${truncated}...and ${remaining} more chars`;
|
|
}
|
|
message += `Body: ${bodyDisplay}`;
|
|
message = message.trim();
|
|
super(message, httpMeta);
|
|
this.name = "SDKError";
|
|
}
|
|
}
|