Skip to content

Commit

Permalink
Rework error to have additional_properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nalanj committed Jan 10, 2025
1 parent 67974ad commit 2ab655a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
10 changes: 6 additions & 4 deletions packages/runner/lib/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ export async function exec(
type: 'script_http_error',
payload: truncateJson(typeof errorResponse === 'string' ? { message: errorResponse } : errorResponse),
status: err.response.status,
upstream_response: {
status: err.response.status,
headers,
body: truncateJson(typeof errorResponse === 'string' ? { message: errorResponse } : errorResponse)
additional_properties: {
upstream_response: {
status: err.response.status,
headers,
body: truncateJson(typeof errorResponse === 'string' ? { message: errorResponse } : errorResponse)
}
}
},
response: null
Expand Down
20 changes: 11 additions & 9 deletions packages/runner/lib/exec.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ describe('Exec', () => {
error: 'Not found'
},
status: 404,
upstream_response: {
body: {
error: 'Not found'
},
headers: {
'content-type': 'application/json',
'x-ratelimit-limit': '100'
},
status: 404
additional_properties: {
upstream_response: {
body: {
error: 'Not found'
},
headers: {
'content-type': 'application/json',
'x-ratelimit-limit': '100'
},
status: 404
}
},
type: 'script_http_error'
});
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/lib/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export class NangoError extends Error {
public readonly status: number = 500;
public readonly type: string;
public payload: Record<string, unknown>;
public additionalProperties: JsonValue = {};
public additional_properties: JsonValue = {};
public override readonly message: string;

constructor(type: string, payload = {}, status?: number, additionalProperties: JsonValue = {}) {
constructor(type: string, payload = {}, status?: number, additional_properties: JsonValue = {}) {
super();

this.type = type;
this.payload = payload;
this.additionalProperties = additionalProperties;
this.additional_properties = additional_properties;

if (status) {
this.status = status;
Expand Down Expand Up @@ -525,7 +525,7 @@ export function isNangoErrorAsJson(obj: unknown): obj is NangoError {

export function deserializeNangoError(err: unknown): NangoError | null {
if (isNangoErrorAsJson(err)) {
return new NangoError(err['type'], err.payload, err.status);
return new NangoError(err['type'], err.payload, err.status, err.additional_properties);
}
return null;
}
6 changes: 5 additions & 1 deletion packages/types/lib/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ export interface RunnerOutputError {
type: string;
payload: Record<string, unknown> | unknown[];
status: number;
upstream_response?: RunnerUpstreamResponse | undefined;
additional_properties?:
| {
upstream_response?: RunnerUpstreamResponse | undefined;
}
| undefined;
}

export interface RunnerUpstreamResponse {
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default defineConfig({
NANGO_LOGS_ES_URL: 'http://fake.com',
NANGO_LOGS_ES_USER: '',
NANGO_LOGS_ES_PWD: '',
NANGO_LOGS_ENABLED: 'false'
NANGO_LOGS_ENABLED: 'false',
NANGO_DB_NAME: 'nango_test'
},
chaiConfig: {
truncateThreshold: 10000
Expand Down

0 comments on commit 2ab655a

Please sign in to comment.