PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.4
Yatra – Travel Booking & Tour Operator Software v3.0.4
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / resources / js / lib / errors.ts

errors.ts in Yatra – Travel Booking & Tour Operator Software 3.0.4, at resources/js/lib/errors.ts

62 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 export interface ErrorRequestInfo {
2 url?: string;
3 method?: string;
4 payload?: string;
5 }
6
7 export interface ErrorContext {
8 details: string;
9 requestInfo?: ErrorRequestInfo;
10 }
11
12 export const getErrorContext = (error: unknown): ErrorContext => {
13 if (!error) {
14 return { details: "" };
15 }
16
17 const requestInfo = (error as any)?.requestInfo as
18 | ErrorRequestInfo
19 | undefined;
20 const maybeResponse = (error as any)?.response;
21
22 const serialize = (value: any): string => {
23 if (value == null) {
24 return "";
25 }
26 if (typeof value === "string") {
27 return value;
28 }
29 try {
30 return JSON.stringify(value, null, 2);
31 } catch {
32 return String(value);
33 }
34 };
35
36 if (maybeResponse?.data !== undefined && maybeResponse?.data !== null) {
37 return {
38 details: serialize(maybeResponse.data),
39 requestInfo,
40 };
41 }
42
43 if (typeof error === "string") {
44 return {
45 details: error,
46 requestInfo,
47 };
48 }
49
50 if (error instanceof Error) {
51 return {
52 details: error.stack || error.message || "",
53 requestInfo,
54 };
55 }
56
57 return {
58 details: serialize(error),
59 requestInfo,
60 };
61 };
62