CS-1264 Improved Logging to debug Lambda Functions#18
CS-1264 Improved Logging to debug Lambda Functions#18jwelborn-sugar wants to merge 2 commits intosugarcrm:masterfrom
Conversation
rogeryang-sugarcrm
left a comment
There was a problem hiding this comment.
Are the Lambda responses logged in Cloudwatch? I did a quick test on the Lambda test console and received the proper response, but I didn't see it logged
src/handlers/add-note-to-case.js
Outdated
| } | ||
| } | ||
| } else { | ||
| body = ErrorMessages.ERROR_CANNOT_MATCH_CASE; |
There was a problem hiding this comment.
Is it a good idea to log why this message is thrown? For this one, we are missing the contactName from the user. I guess this question applies to all areas where this can be thrown
There was a problem hiding this comment.
My update adds a more detailed early return for the missing parameters, and an early return if we match more than one record. We'd only get here now if app.api.call returns a bean without an ID for some reason, and I'm not sure what would cause that.
9b7d60a to
c3d9af8
Compare
| let statusCode = HttpStatus.error; | ||
| let caseId = ''; | ||
| let noteName = ''; | ||
| let body = ''; |
There was a problem hiding this comment.
I just moved these to the top to use them in every early return path for consistency
| let filler = caseNumber ? '' : 'caseNumber '; | ||
| filler += contactId ? '' : 'contactId'; | ||
| body = strUtils.generateMessage(ErrorMessages.TPL_MISSING_REQUIRED_PARAMETERS, filler); | ||
| return { | ||
| statusCode: HttpStatus.preconditionFailed | ||
| statusCode: HttpStatus.preconditionFailed, | ||
| caseId: caseId, | ||
| body: body |
There was a problem hiding this comment.
This return message will tell the user which parameters were missing.
src/handlers/add-note-to-case.js
Outdated
| if (idResponse.data.records.length > 1) { | ||
| body = strUtils.generateMessage(ErrorMessages.TPL_MULTIPLE_RECORDS_MATCHED, 'Case'); | ||
| return { | ||
| statusCode: statusCode, | ||
| caseId: caseId, | ||
| body: body | ||
| }; |
There was a problem hiding this comment.
I think this could live in a case-record-utils that matched the design of our call-record-utils, but for the scope of the ticket I just added logging while trying to avoid changing the code structure.
| async function getCallRecord (contactId) { | ||
| let url = encodeURI(`Calls?filter[0][${CallsConstants.CALLS_AWS_CONTACT_ID}]=${contactId}`); | ||
| url = app.api.buildUrl(url); | ||
| const response = await app.api.call('read', url); |
There was a problem hiding this comment.
These lines are just a whitespace auto-format. I tried to split these into the second commit, but I missed this.
c3d9af8 to
6988ca9
Compare
| response = await axios(request); | ||
|
|
||
| if (response.data) { | ||
| loggerUtils.logSugarApiResponse(response.data); |
There was a problem hiding this comment.
log every return from the Sugar API for debugging purposes
637d54c to
99505a0
Compare
CS-1264 Greatly increase logging in Lambda Functions CS-1264 Log lambda return values
99505a0 to
3aed94e
Compare
| return loggerUtils.logReturnValue({ | ||
| statusCode: HttpStatus.preconditionFailed, | ||
| caseId: caseId, | ||
| body: body | ||
| }); |
There was a problem hiding this comment.
This pattern is used to log return values to cloudwatch for debugging.
| "scripts": { | ||
| "test": "jest --watchAll", | ||
| "lint": "eslint ./src ./__tests__" | ||
| "lint": "eslint --ext .js src/* __tests__/unit/* --fix" |
There was a problem hiding this comment.
this allows us to auto-fix style errors before committing with npm run lint. All of the changes in this commit were from running this command
rogeryang-sugarcrm
left a comment
There was a problem hiding this comment.
Looks good to me
No description provided.