@output.ai/cli 0.7.6 → 0.7.7
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.
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
* Custom ky-based HTTP client for Orval-generated API
|
|
3
3
|
*/
|
|
4
4
|
import type { Options as KyOptions } from 'ky';
|
|
5
|
+
/**
|
|
6
|
+
* Custom error class for HTTP errors with response details
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpError extends Error {
|
|
9
|
+
response: {
|
|
10
|
+
status: number;
|
|
11
|
+
data?: unknown;
|
|
12
|
+
};
|
|
13
|
+
constructor(message: string, response: {
|
|
14
|
+
status: number;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Custom API request options that extend RequestInit with additional config
|
|
7
20
|
*/
|
package/dist/api/http_client.js
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import ky from 'ky';
|
|
5
5
|
import { config } from '#config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Custom error class for HTTP errors with response details
|
|
8
|
+
*/
|
|
9
|
+
export class HttpError extends Error {
|
|
10
|
+
response;
|
|
11
|
+
constructor(message, response) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.response = response;
|
|
14
|
+
this.name = 'HttpError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
6
17
|
const api = ky.create({
|
|
7
18
|
prefixUrl: config.apiUrl,
|
|
8
19
|
timeout: config.requestTimeout,
|
|
@@ -46,5 +57,14 @@ const wrapResponse = (response, data) => ({
|
|
|
46
57
|
export const customFetchInstance = async (url, options) => {
|
|
47
58
|
const response = await api(stripLeadingSlash(url), buildKyOptions(options));
|
|
48
59
|
const data = await response.json().catch(() => undefined);
|
|
60
|
+
// Throw for non-2xx responses so catch handlers can process errors
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const errorData = data;
|
|
63
|
+
const message = errorData?.message || `HTTP ${response.status} error`;
|
|
64
|
+
throw new HttpError(message, {
|
|
65
|
+
status: response.status,
|
|
66
|
+
data: errorData
|
|
67
|
+
});
|
|
68
|
+
}
|
|
49
69
|
return wrapResponse(response, data);
|
|
50
70
|
};
|
|
@@ -65,7 +65,8 @@ export default class WorkflowRun extends Command {
|
|
|
65
65
|
}
|
|
66
66
|
async catch(error) {
|
|
67
67
|
return handleApiError(error, (...args) => this.error(...args), {
|
|
68
|
-
404: 'Workflow not found. Check the workflow name.'
|
|
68
|
+
404: 'Workflow not found. Check the workflow name.',
|
|
69
|
+
500: 'Workflow execution failed.'
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -3,8 +3,24 @@ const DEFAULT_MESSAGES = {
|
|
|
3
3
|
ECONNREFUSED: `Connection refused to ${config.apiUrl}. Is the API server running?`,
|
|
4
4
|
401: 'Authentication failed. Check your API_AUTH_TOKEN.',
|
|
5
5
|
404: 'Resource not found.',
|
|
6
|
+
500: 'Server error.',
|
|
6
7
|
UNKNOWN: 'An unknown error occurred.'
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Extract error type and message from API response data
|
|
11
|
+
*/
|
|
12
|
+
function extractApiErrorDetails(data) {
|
|
13
|
+
const errorData = data;
|
|
14
|
+
if (!errorData?.error && !errorData?.message) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const errorType = errorData.error || 'Error';
|
|
18
|
+
const baseMsg = errorData.message || 'Unknown error';
|
|
19
|
+
const rootCauseLine = errorData.rootCause ?
|
|
20
|
+
`\n${errorData.rootCause.error}: ${errorData.rootCause.message}` :
|
|
21
|
+
'';
|
|
22
|
+
return { errorType, errorMsg: `${baseMsg}.${rootCauseLine}` };
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* Extract detailed error information from fetch errors and their causes
|
|
10
26
|
*/
|
|
@@ -39,6 +55,12 @@ export function handleApiError(error, errorFn, overrides = {}) {
|
|
|
39
55
|
}
|
|
40
56
|
if (apiError.response?.status) {
|
|
41
57
|
const status = apiError.response.status;
|
|
58
|
+
// Extract error details from response body
|
|
59
|
+
const apiErrorDetails = extractApiErrorDetails(apiError.response.data);
|
|
60
|
+
if (apiErrorDetails) {
|
|
61
|
+
const { errorType, errorMsg } = apiErrorDetails;
|
|
62
|
+
errorFn(`${errorType}: ${errorMsg}`, { exit: 1 });
|
|
63
|
+
}
|
|
42
64
|
const message = errorMessages[status];
|
|
43
65
|
if (message) {
|
|
44
66
|
errorFn(message, { exit: 1 });
|