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-5/

Tolerant Error Response Parser

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.

Capabilities

Parses structured JSON error bodies

  • Given a consumed HTTP response with 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. @test

Falls back on unexpected JSON

  • When JSON is well-formed but missing expected error fields, it still returns status info and includes the original body text as responseText instead of failing. @test

Recovers from non-JSON content

  • For plain text or HTML responses, it returns status info and a responseText snippet reflecting the body, and does not throw even when content-type is absent. @test

Handles invalid JSON content gracefully

  • When Content-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

Implementation

@generates

API

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>;

Dependencies { .dependencies }

@backstage/errors { .dependency }

Provides tolerant parsing utilities for consumed HTTP error responses.

Install with Tessl CLI

npx tessl i tessl/npm-backstage--errors

tile.json