@galaxyproject/galaxy-api-client 25.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -0
- package/dist/index.cjs +103 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +37638 -0
- package/dist/index.d.ts +37638 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
- package/src/api-types.ts +106 -0
- package/src/client.test.ts +68 -0
- package/src/client.ts +62 -0
- package/src/dist/api-types.js +46 -0
- package/src/dist/example.js +258 -0
- package/src/example.ts +105 -0
- package/src/index.ts +31 -0
- package/src/integration.test.ts +118 -0
- package/src/utils/error.ts +38 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P
|
|
7
|
+
? value
|
|
8
|
+
: new P(function (resolve) {
|
|
9
|
+
resolve(value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rejected(value) {
|
|
21
|
+
try {
|
|
22
|
+
step(generator["throw"](value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
29
|
+
}
|
|
30
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
var __generator =
|
|
34
|
+
(this && this.__generator) ||
|
|
35
|
+
function (thisArg, body) {
|
|
36
|
+
var _ = {
|
|
37
|
+
label: 0,
|
|
38
|
+
sent: function () {
|
|
39
|
+
if (t[0] & 1) throw t[1];
|
|
40
|
+
return t[1];
|
|
41
|
+
},
|
|
42
|
+
trys: [],
|
|
43
|
+
ops: [],
|
|
44
|
+
},
|
|
45
|
+
f,
|
|
46
|
+
y,
|
|
47
|
+
t,
|
|
48
|
+
g;
|
|
49
|
+
return (
|
|
50
|
+
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
|
|
51
|
+
typeof Symbol === "function" &&
|
|
52
|
+
(g[Symbol.iterator] = function () {
|
|
53
|
+
return this;
|
|
54
|
+
}),
|
|
55
|
+
g
|
|
56
|
+
);
|
|
57
|
+
function verb(n) {
|
|
58
|
+
return function (v) {
|
|
59
|
+
return step([n, v]);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function step(op) {
|
|
63
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
64
|
+
while (_)
|
|
65
|
+
try {
|
|
66
|
+
if (
|
|
67
|
+
((f = 1),
|
|
68
|
+
y &&
|
|
69
|
+
(t =
|
|
70
|
+
op[0] & 2
|
|
71
|
+
? y["return"]
|
|
72
|
+
: op[0]
|
|
73
|
+
? y["throw"] || ((t = y["return"]) && t.call(y), 0)
|
|
74
|
+
: y.next) &&
|
|
75
|
+
!(t = t.call(y, op[1])).done)
|
|
76
|
+
)
|
|
77
|
+
return t;
|
|
78
|
+
if (((y = 0), t)) op = [op[0] & 2, t.value];
|
|
79
|
+
switch (op[0]) {
|
|
80
|
+
case 0:
|
|
81
|
+
case 1:
|
|
82
|
+
t = op;
|
|
83
|
+
break;
|
|
84
|
+
case 4:
|
|
85
|
+
_.label++;
|
|
86
|
+
return { value: op[1], done: false };
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [0];
|
|
91
|
+
continue;
|
|
92
|
+
case 7:
|
|
93
|
+
op = _.ops.pop();
|
|
94
|
+
_.trys.pop();
|
|
95
|
+
continue;
|
|
96
|
+
default:
|
|
97
|
+
if (
|
|
98
|
+
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
|
|
99
|
+
(op[0] === 6 || op[0] === 2)
|
|
100
|
+
) {
|
|
101
|
+
_ = 0;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
105
|
+
_.label = op[1];
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
109
|
+
_.label = t[1];
|
|
110
|
+
t = op;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (t && _.label < t[2]) {
|
|
114
|
+
_.label = t[2];
|
|
115
|
+
_.ops.push(op);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
if (t[2]) _.ops.pop();
|
|
119
|
+
_.trys.pop();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
op = body.call(thisArg, _);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
op = [6, e];
|
|
125
|
+
y = 0;
|
|
126
|
+
} finally {
|
|
127
|
+
f = t = 0;
|
|
128
|
+
}
|
|
129
|
+
if (op[0] & 5) throw op[1];
|
|
130
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.__esModule = true;
|
|
134
|
+
exports.createDataset = exports.getToolById = exports.getTools = void 0;
|
|
135
|
+
// Example usage of the Galaxy API client
|
|
136
|
+
var index_1 = require("./index");
|
|
137
|
+
//
|
|
138
|
+
// Basic usage - just provide a base URL
|
|
139
|
+
//
|
|
140
|
+
var basicApi = index_1.createGalaxyApi("https://usegalaxy.org");
|
|
141
|
+
//
|
|
142
|
+
// Advanced usage - with API key authentication and custom headers
|
|
143
|
+
//
|
|
144
|
+
var authenticatedApi = index_1.createGalaxyApi({
|
|
145
|
+
baseUrl: "https://usegalaxy.org",
|
|
146
|
+
apiKey: "your-api-key-here",
|
|
147
|
+
headers: {
|
|
148
|
+
Accept: "application/json",
|
|
149
|
+
"User-Agent": "GalaxyClientApp/1.0",
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
//
|
|
153
|
+
// Example with request options (timeouts, credentials, etc.)
|
|
154
|
+
//
|
|
155
|
+
var apiWithOptions = index_1.createGalaxyApi({
|
|
156
|
+
baseUrl: "https://usegalaxy.org",
|
|
157
|
+
fetchOptions: {
|
|
158
|
+
credentials: "include",
|
|
159
|
+
cache: "no-cache",
|
|
160
|
+
timeout: 30000,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
// Example function to get a list of tools
|
|
164
|
+
function getTools() {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var _a, data, error, sections, _i, data_1, tool, section;
|
|
167
|
+
return __generator(this, function (_b) {
|
|
168
|
+
switch (_b.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
return [4 /*yield*/, basicApi.GET("/api/tools")];
|
|
171
|
+
case 1:
|
|
172
|
+
(_a = _b.sent()), (data = _a.data), (error = _a.error);
|
|
173
|
+
if (error) {
|
|
174
|
+
console.error("Error fetching tools:", error);
|
|
175
|
+
return [2 /*return*/, []];
|
|
176
|
+
}
|
|
177
|
+
// Log tool count
|
|
178
|
+
console.log("Found " + data.length + " tools");
|
|
179
|
+
sections = {};
|
|
180
|
+
for (_i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
181
|
+
tool = data_1[_i];
|
|
182
|
+
section = tool.panel_section_name || "Ungrouped";
|
|
183
|
+
if (!sections[section]) sections[section] = [];
|
|
184
|
+
sections[section].push(tool);
|
|
185
|
+
}
|
|
186
|
+
// Print summary
|
|
187
|
+
Object.keys(sections).forEach(function (section) {
|
|
188
|
+
console.log(section + ": " + sections[section].length + " tools");
|
|
189
|
+
});
|
|
190
|
+
return [2 /*return*/, data];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
exports.getTools = getTools;
|
|
196
|
+
// Example function to get a specific tool by ID
|
|
197
|
+
function getToolById(id) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
199
|
+
var _a, data, error;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0:
|
|
203
|
+
return [
|
|
204
|
+
4 /*yield*/,
|
|
205
|
+
authenticatedApi.GET("/api/tools/{tool_id}", {
|
|
206
|
+
params: {
|
|
207
|
+
path: {
|
|
208
|
+
tool_id: id,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
];
|
|
213
|
+
case 1:
|
|
214
|
+
(_a = _b.sent()), (data = _a.data), (error = _a.error);
|
|
215
|
+
if (error || !data) {
|
|
216
|
+
console.error("Error fetching tool:", error);
|
|
217
|
+
return [2 /*return*/, null];
|
|
218
|
+
}
|
|
219
|
+
return [2 /*return*/, data];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
exports.getToolById = getToolById;
|
|
225
|
+
// Example function to create a dataset in a history
|
|
226
|
+
function createDataset(historyId, name, content) {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
228
|
+
var _a, data, error;
|
|
229
|
+
return __generator(this, function (_b) {
|
|
230
|
+
switch (_b.label) {
|
|
231
|
+
case 0:
|
|
232
|
+
return [
|
|
233
|
+
4 /*yield*/,
|
|
234
|
+
apiWithOptions.POST("/api/histories/{history_id}/contents", {
|
|
235
|
+
params: {
|
|
236
|
+
path: {
|
|
237
|
+
history_id: historyId,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
body: {
|
|
241
|
+
name: name,
|
|
242
|
+
content: content,
|
|
243
|
+
type: "file",
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
];
|
|
247
|
+
case 1:
|
|
248
|
+
(_a = _b.sent()), (data = _a.data), (error = _a.error);
|
|
249
|
+
if (error) {
|
|
250
|
+
console.error("Error creating dataset:", error);
|
|
251
|
+
return [2 /*return*/, null];
|
|
252
|
+
}
|
|
253
|
+
return [2 /*return*/, data];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
exports.createDataset = createDataset;
|
package/src/example.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Example usage of the Galaxy API client
|
|
2
|
+
import { createGalaxyApi } from "./index";
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
// Basic usage - just provide a base URL
|
|
6
|
+
//
|
|
7
|
+
const basicApi = createGalaxyApi("https://usegalaxy.org");
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
// Advanced usage - with API key authentication and custom headers
|
|
11
|
+
//
|
|
12
|
+
const authenticatedApi = createGalaxyApi({
|
|
13
|
+
baseUrl: "https://usegalaxy.org",
|
|
14
|
+
apiKey: "your-api-key-here",
|
|
15
|
+
headers: {
|
|
16
|
+
Accept: "application/json",
|
|
17
|
+
"User-Agent": "GalaxyClientApp/1.0",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
//
|
|
22
|
+
// Example with request options (timeouts, credentials, etc.)
|
|
23
|
+
//
|
|
24
|
+
const apiWithOptions = createGalaxyApi({
|
|
25
|
+
baseUrl: "https://usegalaxy.org",
|
|
26
|
+
fetchOptions: {
|
|
27
|
+
credentials: "include", // Include cookies for CORS requests
|
|
28
|
+
cache: "no-cache", // Don't cache responses
|
|
29
|
+
timeout: 30000, // 30 second timeout
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Example function to get a list of tools
|
|
34
|
+
async function getTools() {
|
|
35
|
+
// Using the basic API
|
|
36
|
+
const { data, error } = await basicApi.GET("/api/tools");
|
|
37
|
+
|
|
38
|
+
if (error) {
|
|
39
|
+
console.error("Error fetching tools:", error);
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Log tool count
|
|
44
|
+
console.log(`Found ${data.length} tools`);
|
|
45
|
+
|
|
46
|
+
// Group tools by section
|
|
47
|
+
const sections: Record<string, any[]> = {};
|
|
48
|
+
for (const tool of data) {
|
|
49
|
+
const section = tool.panel_section_name || "Ungrouped";
|
|
50
|
+
if (!sections[section]) sections[section] = [];
|
|
51
|
+
sections[section].push(tool);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Print summary
|
|
55
|
+
Object.keys(sections).forEach((section) => {
|
|
56
|
+
console.log(`${section}: ${sections[section].length} tools`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Example function to get a specific tool by ID
|
|
63
|
+
async function getToolById(id: string) {
|
|
64
|
+
// Using the authenticated API
|
|
65
|
+
const { data, error } = await authenticatedApi.GET("/api/tools/{tool_id}", {
|
|
66
|
+
params: {
|
|
67
|
+
path: {
|
|
68
|
+
tool_id: id,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (error || !data) {
|
|
74
|
+
console.error("Error fetching tool:", error);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Example function to create a dataset in a history
|
|
82
|
+
async function createDataset(historyId: string, name: string, content: string) {
|
|
83
|
+
// Using the API with custom options
|
|
84
|
+
const { data, error } = await apiWithOptions.POST("/api/histories/{history_id}/contents", {
|
|
85
|
+
params: {
|
|
86
|
+
path: {
|
|
87
|
+
history_id: historyId,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
body: {
|
|
91
|
+
name,
|
|
92
|
+
content,
|
|
93
|
+
type: "file",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (error) {
|
|
98
|
+
console.error("Error creating dataset:", error);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return data;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { getTools, getToolById, createDataset };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Galaxy Client API
|
|
3
|
+
* A client library for the Galaxy API
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createGalaxyApi, type GalaxyApiClient } from "./client";
|
|
7
|
+
import { errorMessageAsString } from "./utils/error";
|
|
8
|
+
|
|
9
|
+
// Re-export all the types from our type compatibility layer
|
|
10
|
+
export * from "./api-types";
|
|
11
|
+
|
|
12
|
+
// SimpleError class for error handling
|
|
13
|
+
export class SimpleError extends Error {
|
|
14
|
+
constructor(message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "GalaxyApiError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Re-export the client functions
|
|
21
|
+
export { createGalaxyApi, type GalaxyApiClient };
|
|
22
|
+
|
|
23
|
+
// For backward compatibility - creates a client with default settings
|
|
24
|
+
export function GalaxyApi() {
|
|
25
|
+
return createGalaxyApi();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Utility function to format error messages
|
|
29
|
+
export function formatErrorMessage(error: any): string {
|
|
30
|
+
return errorMessageAsString(error);
|
|
31
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { type HistorySummary } from "./api-types";
|
|
3
|
+
|
|
4
|
+
// Set up mock responses
|
|
5
|
+
const mockHistories: HistorySummary[] = [
|
|
6
|
+
{
|
|
7
|
+
id: "1",
|
|
8
|
+
name: "Test History 1",
|
|
9
|
+
deleted: false,
|
|
10
|
+
purged: false,
|
|
11
|
+
archived: false,
|
|
12
|
+
tags: [],
|
|
13
|
+
model_class: "History",
|
|
14
|
+
url: "/api/histories/1",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "2",
|
|
18
|
+
name: "Test History 2",
|
|
19
|
+
deleted: false,
|
|
20
|
+
purged: false,
|
|
21
|
+
archived: false,
|
|
22
|
+
tags: ["test"],
|
|
23
|
+
model_class: "History",
|
|
24
|
+
url: "/api/histories/2",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// Create a mock API client with typed responses
|
|
29
|
+
const mockApiClient = {
|
|
30
|
+
GET: vi.fn().mockImplementation((path, options) => {
|
|
31
|
+
if (path === "/api/histories") {
|
|
32
|
+
return Promise.resolve({
|
|
33
|
+
data: mockHistories,
|
|
34
|
+
error: null,
|
|
35
|
+
response: new Response(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (path === "/api/histories/{history_id}" && options?.params?.path?.history_id === "1") {
|
|
39
|
+
return Promise.resolve({
|
|
40
|
+
data: mockHistories[0],
|
|
41
|
+
error: null,
|
|
42
|
+
response: new Response(),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return Promise.resolve({
|
|
46
|
+
data: null,
|
|
47
|
+
error: { status: 404, message: "Not found" },
|
|
48
|
+
response: new Response(),
|
|
49
|
+
});
|
|
50
|
+
}),
|
|
51
|
+
POST: vi.fn(),
|
|
52
|
+
PUT: vi.fn(),
|
|
53
|
+
DELETE: vi.fn(),
|
|
54
|
+
PATCH: vi.fn(),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Setup mocks before importing the modules that use them
|
|
58
|
+
vi.mock("openapi-fetch", () => {
|
|
59
|
+
return {
|
|
60
|
+
default: vi.fn().mockImplementation(() => mockApiClient),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Import the modules after setting up mocks
|
|
65
|
+
import { createGalaxyApi, GalaxyApi } from "./index";
|
|
66
|
+
|
|
67
|
+
describe("Galaxy API Integration", () => {
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
vi.clearAllMocks();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("exports the createGalaxyApi function", () => {
|
|
73
|
+
expect(typeof createGalaxyApi).toBe("function");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("exports the backward-compatible GalaxyApi function", () => {
|
|
77
|
+
expect(typeof GalaxyApi).toBe("function");
|
|
78
|
+
expect(GalaxyApi()).toEqual(mockApiClient);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("retrieves histories with proper typing", async () => {
|
|
82
|
+
const api = createGalaxyApi();
|
|
83
|
+
const { data, error } = await api.GET("/api/histories");
|
|
84
|
+
|
|
85
|
+
expect(error).toBeNull();
|
|
86
|
+
expect(data).toEqual(mockHistories);
|
|
87
|
+
|
|
88
|
+
if (data) {
|
|
89
|
+
// This is a type check - if TypeScript can compile this,
|
|
90
|
+
// it means the types are working correctly
|
|
91
|
+
const firstHistory = data[0];
|
|
92
|
+
expect(firstHistory.id).toBe("1");
|
|
93
|
+
expect(firstHistory.name).toBe("Test History 1");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("retrieves a single history by ID", async () => {
|
|
98
|
+
const api = createGalaxyApi();
|
|
99
|
+
const { data, error } = await api.GET("/api/histories/{history_id}", {
|
|
100
|
+
params: {
|
|
101
|
+
path: {
|
|
102
|
+
history_id: "1",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(error).toBeNull();
|
|
108
|
+
expect(data).toEqual(mockHistories[0]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("handles errors properly", async () => {
|
|
112
|
+
const api = createGalaxyApi();
|
|
113
|
+
const { data, error } = await api.GET("/api/nonexistent");
|
|
114
|
+
|
|
115
|
+
expect(data).toBeNull();
|
|
116
|
+
expect(error).toEqual({ status: 404, message: "Not found" });
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple error handling utilities for Galaxy Client API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert various error formats to a readable string message
|
|
7
|
+
*/
|
|
8
|
+
export function errorMessageAsString(error: any): string {
|
|
9
|
+
if (typeof error === "string") {
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (error instanceof Error) {
|
|
14
|
+
return error.message;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (error && typeof error === "object") {
|
|
18
|
+
// Handle API response errors
|
|
19
|
+
if (error.status && error.error) {
|
|
20
|
+
return `API Error (${error.status}): ${error.error}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Handle response objects with error message
|
|
24
|
+
if (error.message) {
|
|
25
|
+
return error.message;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Try to stringify the error object
|
|
29
|
+
try {
|
|
30
|
+
return JSON.stringify(error);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// Fall back to object inspection
|
|
33
|
+
return String(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return "Unknown error";
|
|
38
|
+
}
|