Skip to content

v0.3.4 - Enhanced Error Handling

Choose a tag to compare

@campearce campearce released this 07 Jan 15:25
· 11 commits to main since this release

What's New

Enhanced Error Handling with Response Body Parsing

ZebraError now automatically parses and exposes the HTTP response body, making it easier to debug API errors without manually reading the response.

New responseBody Property

When catching a ZebraError, you can now access the pre-parsed response body directly:

import { ZebraClient, ZebraError } from '@irly-tech/zebra-client';

try {
    await client.sensors.get('invalid-id');
} catch (error) {
    if (error instanceof ZebraError) {
        console.log('Status:', error.statusCode);        // e.g., 404
        console.log('Message:', error.message);          // e.g., "Zebra API error: Not Found"

        // Access the pre-parsed response body (no async call needed!)
        if (typeof error.responseBody === 'object') {
            // JSON error response from the API
            console.log('Error code:', error.responseBody.code);
            console.log('Details:', error.responseBody.message);
        } else if (typeof error.responseBody === 'string') {
            // Plain text error response
            console.log('Error text:', error.responseBody);
        }

        // Raw Response still available for advanced use cases
        console.log('Headers:', error.response?.headers.get('x-request-id'));
    }
}

New Exports

  • ZebraErrorBody - Type for the parsed response body (Record<string, unknown> | string | undefined)
  • ZebraError.fromResponse() - Static factory method for creating errors with parsed bodies

Improved Documentation

  • Added @throws {ZebraError} JSDoc annotations to all API methods
  • Added comprehensive usage examples in the ZebraError class documentation

Full Changelog: v0.3.3...v0.3.4