import { ShadeError } from '@shade/core';

/**
 * Thrown when a bridge transport fails — connect rejected, malformed wire
 * data, abrupt disconnect with no reconnect possible, etc.
 *
 * Carries `httpStatus` when the failure has a recognizable HTTP root cause
 * so a fallback chain can decide whether to skip to the next bridge.
 */
export class BridgeError extends ShadeError {
  constructor(message: string, public readonly httpStatus?: number) {
    super('SHADE_BRIDGE_ERROR', message);
    this.name = 'BridgeError';
  }

  override toJSON(): { name: string; code: string; message: string; httpStatus?: number } {
    const base = super.toJSON();
    if (this.httpStatus !== undefined) {
      return { ...base, httpStatus: this.httpStatus };
    }
    return base;
  }
}
