Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Increase log verbosity #70

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/Dialogflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppSetting } from '../config/Settings';
import { DialogflowJWT, DialogflowRequestType, DialogflowUrl, IDialogflowAccessToken, IDialogflowEvent, IDialogflowMessage, IDialogflowQuickReplies, LanguageCode } from '../enum/Dialogflow';
import { Headers } from '../enum/Http';
import { Logs } from '../enum/Logs';
import { base64urlEncode } from './Helper';
import { base64urlEncode, stringifyError } from './Helper';
import { createHttpRequest } from './Http';
import { updateRoomCustomFields } from './Room';
import { getAppSettingValue } from './Settings';
Expand All @@ -32,9 +32,16 @@ class DialogflowClass {

try {
const response = await http.post(serverURL, httpRequestContent);
if (!response) {
throw new Error('Failed to get any response from the Dialogflow api. Please check if you server is able to connect to public n/w');
}
if (!response.statusCode.toString().startsWith('2') || !response.data) {
throw new Error(`Invalid response received from Dialogflow api. Response: ${ response.content }`);
}

return this.parseRequest(response.data);
} catch (error) {
throw new Error(`${ Logs.HTTP_REQUEST_ERROR }`);
throw new Error(`${ Logs.HTTP_REQUEST_ERROR }. Details: ${ error.message }. Raw Error: ${ stringifyError(error) }`);
}
}

Expand Down Expand Up @@ -166,7 +173,7 @@ class DialogflowClass {

return accessToken.token;
} catch (error) {
throw Error(Logs.ACCESS_TOKEN_ERROR + error);
throw Error(`${ Logs.ACCESS_TOKEN_ERROR }. Raw Error: ${ stringifyError(error) }`);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ export const uuid = (): string => {
export const escapeRegExp = (str: string): string => {
return str.replace(/[.*+?^${}()|[\]\\\/]/g, '\\$&'); // $& means the whole matched string
};

export const stringifyError = (error: Error): string => (JSON.stringify(error, Object.getOwnPropertyNames(error)));