ckb-cell / rgbpp-sdk

Utilities for Bitcoin and RGB++ asset integration
ISC License
53 stars 16 forks source link

feat(service): throw service error with context #149

Closed ShookLyngs closed 4 months ago

ShookLyngs commented 4 months ago

Changes

Related issues

Details

You can now find context in the BtcAssetsApiError if the error was thrown from a request:

try { 
  ... 
} catch (e) {
  if (e instanceof BtcAssetsApiError) {
    console.log(e.context?.request);
    console.log(e.context?.response);
  }
}

This is the type of e.context:

interface BtcAssetsApiContext {
  request: {
    url: string;
    body?: Record<string, any>;
    params?: Record<string, any>;
  };
  response: {
    status: number;
    data?: Record<string, any> | string;
  };
}