Skip to content

Commit

Permalink
[IMPROVE] Increase log verbosity (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 authored Nov 30, 2021
1 parent 715c02d commit 26ed342
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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 @@ -167,7 +174,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)));

0 comments on commit 26ed342

Please sign in to comment.