import { HttpException, HttpStatus } from '@nestjs/common';
import { CAPIErrorCode } from './capi-error-codes';

/**
 * 携带语义错误码的 HttpException。
 * 用于 CAPI 统一错误响应，iOS 端通过 errorCode 做强类型判断。
 */
export class CapiException extends HttpException {
  readonly errorCode: CAPIErrorCode;

  constructor(
    errorCode: CAPIErrorCode,
    message: string,
    status: HttpStatus = HttpStatus.BAD_REQUEST,
  ) {
    super({ message, errorCode }, status);
    this.errorCode = errorCode;
  }
}
