# yatra/3.0.15/resources/js/lib/errors.ts

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.15. 62 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.15/code/resources/js/lib/errors.ts
- Raw: https://pluginprobe.com/plugins/yatra/3.0.15/raw/resources/js/lib/errors.ts
- Modified: 2026-04-14T03:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.15/code/resources/js/lib/errors.ts#L10-L20`.

```typescript
export interface ErrorRequestInfo {
  url?: string;
  method?: string;
  payload?: string;
}

export interface ErrorContext {
  details: string;
  requestInfo?: ErrorRequestInfo;
}

export const getErrorContext = (error: unknown): ErrorContext => {
  if (!error) {
    return { details: "" };
  }

  const requestInfo = (error as any)?.requestInfo as
    | ErrorRequestInfo
    | undefined;
  const maybeResponse = (error as any)?.response;

  const serialize = (value: any): string => {
    if (value == null) {
      return "";
    }
    if (typeof value === "string") {
      return value;
    }
    try {
      return JSON.stringify(value, null, 2);
    } catch {
      return String(value);
    }
  };

  if (maybeResponse?.data !== undefined && maybeResponse?.data !== null) {
    return {
      details: serialize(maybeResponse.data),
      requestInfo,
    };
  }

  if (typeof error === "string") {
    return {
      details: error,
      requestInfo,
    };
  }

  if (error instanceof Error) {
    return {
      details: error.stack || error.message || "",
      requestInfo,
    };
  }

  return {
    details: serialize(error),
    requestInfo,
  };
};

```
