fix: check data is present before reading errors #309
+29
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
npm testpasses (tip:npm run lint-fixcan correct most style issues)Received a user report where a client-side disconnection results in:
I haven't been able to reproduce a client-side disconnection that results in an axios error that includes a
responseatnode-sdk-core/lib/request-wrapper.ts
Line 378 in 6a13d1d
but doesn't have
dataatnode-sdk-core/lib/request-wrapper.ts
Line 391 in 6a13d1d
Nonetheless
node-sdk-core/lib/request-wrapper.ts
Line 648 in 6a13d1d
(Note that
responsehere isresponse.datafrom theformatErrorfunction)since
parseServiceErrorMessagedeclaresresponse: any, but does not check forundefinedornull(which are permitted byany) before trying to access properties.This PR adds a guard clause to prevent accessing properties in the event the passed
response.data->responsewas not defined to avoid theTypeError.I added a test that fails before the change and passes after it validating that an error object without
response.datadoes not throw.Note: the build failures appear unrelated to this change, but rather an issue with a missing dependency.this worked on a re-run