Common utilities for error handling within Backstage with structured error classes and serialization functions
63
Create a helper that turns request issues into standardized HTTP-style errors using the dependency's built-in classes.
badRequest issue with the message "Invalid payload", produce the dependency's HTTP error type for invalid client input, carrying the same message and optional cause. @testunauthenticated issue with the message "Missing token", produce the dependency's unauthorized HTTP error type with the provided message and optional cause. @testforbidden issue with the message "Admin role required", produce the dependency's forbidden HTTP error type with the provided message and optional cause. @testnotFound issue with the message "User user-17 not found", produce the dependency's missing-resource HTTP error type with the provided message and optional cause. @testconflict issue with the message "Version mismatch for cart-44", produce the dependency's conflict HTTP error type with the provided message and optional cause. @test@generates
export type RequestIssue =
| { kind: 'badRequest'; message: string; cause?: Error }
| { kind: 'unauthenticated'; message: string; cause?: Error }
| { kind: 'forbidden'; message: string; cause?: Error }
| { kind: 'notFound'; message: string; cause?: Error }
| { kind: 'conflict'; message: string; cause?: Error };
/**
* Builds a standardized HTTP-style Error instance for the given issue,
* using the dependency's pre-defined error class that corresponds to the kind.
*/
export function buildHttpError(issue: RequestIssue): Error;Provides standardized HTTP-style error classes for common web error scenarios.
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