Skip to content

Commit

Permalink
Gh #750 full error (#787)
Browse files Browse the repository at this point in the history
* [gh-#750] show pretty error stack

* [gh-#750] remove stack
  • Loading branch information
khaliqgant authored Jul 18, 2023
1 parent b588b65 commit 0d7164b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
11 changes: 6 additions & 5 deletions packages/node-client/bin/proxy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Nango } from '../dist/index.js';
const nango = new Nango({ host: 'http://localhost:3003' });
const args = process.argv.slice(2);

const nango = new Nango({ host: 'http://localhost:3003', secretKey: args[0] });

nango
.proxy({
providerConfigKey: args[0],
connectionId: args[1],
method: args[2],
endpoint: args[3],
providerConfigKey: args[1],
connectionId: args[2],
method: args[3],
endpoint: args[4],
retries: 3,
data: {
summary: 'TEST',
Expand Down
31 changes: 21 additions & 10 deletions packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,17 @@ class OAuthController {

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownAuthMode(template.auth_mode));
} catch (e) {
const prettyError = JSON.stringify(e, ['message', 'name'], 2);
await createActivityLogMessage({
level: 'error',
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
timestamp: Date.now()
});

errorManager.report(e, { accountId: accountId });

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
}
}

Expand Down Expand Up @@ -383,10 +384,14 @@ class OAuthController {
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownGrantType(grantType));
}
} catch (error: any) {
const prettyError = JSON.stringify(error, ['message', 'name'], 2);

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;

await createActivityLogMessage({
level: 'error',
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message + ' ' + error.code ?? '',
content,
timestamp: Date.now(),
auth_mode: template.auth_mode,
url: callbackUrl,
Expand All @@ -395,7 +400,7 @@ class OAuthController {
}
});

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
}
}

Expand Down Expand Up @@ -537,22 +542,26 @@ class OAuthController {
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownAuthMode(session.authMode));
} catch (e) {
const accountId = (await environmentService.getAccountIdFromEnvironment(session.environmentId)) as number;
const prettyError = JSON.stringify(e, ['message', 'name'], 2);

errorManager.report(e, {
accountId,
metadata: errorManager.getExpressRequestContext(req)
});

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;

await createActivityLogMessage({
level: 'error',
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message,
content,
timestamp: Date.now(),
params: {
...errorManager.getExpressRequestContext(req)
}
});

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
}
}

Expand Down Expand Up @@ -706,16 +715,17 @@ class OAuthController {
return wsClient.notifySuccess(res, wsClientId, providerConfigKey, connectionId);
} catch (e) {
const accountId = (await environmentService.getAccountIdFromEnvironment(session.environmentId)) as number;
const prettyError = JSON.stringify(e, ['message', 'name'], 2);
errorManager.report(e, { accountId });

await createActivityLogMessageAndEnd({
level: 'error',
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
timestamp: Date.now()
});

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
}
}

Expand Down Expand Up @@ -780,15 +790,16 @@ class OAuthController {
})
.catch(async (e) => {
errorManager.report(e, { accountId });
const prettyError = JSON.stringify(e, ['message', 'name'], 2);

await createActivityLogMessageAndEnd({
level: 'error',
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
timestamp: Date.now()
});

return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return wsClient.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/utils/web-socket-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class WSErrBuilder {
};
}

public static UnkownError(): WSErr {
public static UnkownError(errorMessage?: string): WSErr {
return {
type: 'unknown_err',
message: `Unkown error during the Oauth flow.`
message: `Unkown error during the Oauth flow.${errorMessage ? ' ' + errorMessage : ''}`
};
}

Expand Down

0 comments on commit 0d7164b

Please sign in to comment.