Open mickmister opened 2 years ago
There are lots several 7-line blocks in src/restapi/fConnect.ts for handling errors:
https://github.com/mattermost/mattermost-app-zendesk/blob/3b94866d2f8e1e0450515d47f3817db55c7b4785/src/restapi/fConnect.ts#L114-L120
This could be made into a one-liner by using a helper function:
await tryCallResponseWithMessage(ppClient.storeOauth2User(storedToken), 'fOauth2Complete - Unable to store oauth2user', res);
which could be implemented as
export async function tryCallResponseWithMessage(promise, message, res) { return promise.catch((error) => { const fullMessage = message + ': ' + error.message; const callResponse = newErrorCallResponseWithMessage(fullMessage); res.json(callResponse); }); }
This improvement would make the code a lot easier to read. This can probably be applied to many places of the application.
Working on it
Awesome, thanks you @bdoodo :tada:
There are lots several 7-line blocks in src/restapi/fConnect.ts for handling errors:
https://github.com/mattermost/mattermost-app-zendesk/blob/3b94866d2f8e1e0450515d47f3817db55c7b4785/src/restapi/fConnect.ts#L114-L120
This could be made into a one-liner by using a helper function:
which could be implemented as
This improvement would make the code a lot easier to read. This can probably be applied to many places of the application.