Common utilities for error handling within Backstage with structured error classes and serialization functions
63
A library for producing structured error payloads from failed HTTP responses without throwing during parsing. The parser always echoes the original status code and text.
application/json content that includes an error object (with at least message) and optional response metadata, it returns a parsed payload combining status code/text, the remote error details (including optional name, stack, and cause), and the remote response field without stripping nested causes. @testresponseText instead of failing. @testresponseText snippet reflecting the body, and does not throw even when content-type is absent. @testContent-Type indicates JSON but the body is invalid, it returns status info and a responseText describing the parsing failure while still completing the promise. @test@generates
export interface ConsumedResponse {
status: number;
statusText: string;
headers: Record<string, string | string[]>;
body: string;
url?: string;
}
export interface ParsedErrorBody {
statusCode: number;
statusText: string;
body?: {
error?: {
name?: string;
message?: string;
stack?: string;
cause?: unknown;
};
response?: unknown;
};
responseText?: string;
}
export function parseErrorBody(consumed: ConsumedResponse): Promise<ParsedErrorBody>;Provides tolerant parsing utilities for consumed HTTP error responses.
Install with Tessl CLI
npx tessl i tessl/npm-backstage--errorsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10