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

Handle null response in onError handler #6

Open
glenn-allen opened this issue Jan 27, 2022 · 0 comments
Open

Handle null response in onError handler #6

glenn-allen opened this issue Jan 27, 2022 · 0 comments

Comments

@glenn-allen
Copy link

Hi guys,

Just discovered an error that might be occurring since we upgraded to Node v16.13.2 (from 12), though it's potentially been happening for previous versions and we've only noticed it now because it now crashes our servers - due to the unhandled exception change in Node.

Anyway, it seems the onError handler isn't safe if the response is null.

var onError = function(error, response, body) {
this.log('API request error: ' + error);
this.log('API request response:', body);
this.log('API request error: ' + response.statusCode);

See the stack trace below:

/home/ubuntu/www/node_modules/filepreviews/lib/index.js:92
    this.log('API request error: ' + response.statusCode);
                                              ^

TypeError: Cannot read properties of undefined (reading 'statusCode')
    at FilePreviews.<anonymous> (/home/ubuntu/www/node_modules/filepreviews/lib/index.js:92:47)
    at Request._callback (/home/ubuntu/www/node_modules/filepreviews/lib/index.js:135:9)
    at self.callback (/home/ubuntu/www/node_modules/request/request.js:185:22)
    at Request.emit (node:events:390:28)
    at Request.emit (node:domain:475:12)
    at Request.onRequestError (/home/ubuntu/www/node_modules/request/request.js:877:8)
    at ClientRequest.emit (node:events:390:28)
    at ClientRequest.emit (node:domain:475:12)
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:390:28)
    at TLSSocket.emit (node:domain:475:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant