CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-backstage--errors

Common utilities for error handling within Backstage with structured error classes and serialization functions

63

1.28x
Overview
Eval results
Files

task.mdevals/scenario-8/

HTTP Error Translator

Create a helper that turns request issues into standardized HTTP-style errors using the dependency's built-in classes.

Capabilities

Converts validation failures to client errors

  • For a 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. @test

Enforces authentication and authorization boundaries

  • For an unauthenticated issue with the message "Missing token", produce the dependency's unauthorized HTTP error type with the provided message and optional cause. @test
  • For a forbidden issue with the message "Admin role required", produce the dependency's forbidden HTTP error type with the provided message and optional cause. @test

Reports missing resources

  • For a notFound 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. @test

Prevents conflicting writes

  • For a conflict 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

Implementation

@generates

API

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;

Dependencies { .dependencies }

@backstage/errors { .dependency }

Provides standardized HTTP-style error classes for common web error scenarios.

Install with Tessl CLI

npx tessl i tessl/npm-backstage--errors

tile.json