You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If my geo data provider fails to give a healthy response, the error handling is not correct. I'm seeing errors of the following form
Error getting geography information for San Francisco, CA, USA
Error: HttpError: body used already for: https://nominatim.openstreetmap.org/search?addressdetails=1&q=San+Francisco%2C+CA%2C+USA&format=json
at /home/styff/platform/node_modules/node-geocoder/lib/httpadapter/fetchadapter.js:58:15
at tryCatcher (/home/stuff/platform/node_modules/bluebird/js/release/util.js:16:23)
Because the response is a stream, calling res.json() and then res.text() is not valid. The recommended solution seems to be either:
pre-check the response's status code before calling res.json() to reduce the likelihood of error
just call res.text() so there's always a response assigned to a variable, and then call JSON.parse(the-text) and wrap that call in a try-catch. If the try-catch fails, then you can print the-text without trying to read the stream twice.
The text was updated successfully, but these errors were encountered:
Ephigenia
added a commit
to Ephigenia/node-geocoder
that referenced
this issue
Feb 27, 2023
If my geo data provider fails to give a healthy response, the error handling is not correct. I'm seeing errors of the following form
This seems to be the same as node-fetch/node-fetch#533. The cause is this block in https://github.com/nchaulet/node-geocoder/blob/master/lib/httpadapter/fetchadapter.js:
Because the response is a stream, calling
res.json()
and thenres.text()
is not valid. The recommended solution seems to be either:res.json()
to reduce the likelihood of errorres.text()
so there's always a response assigned to a variable, and then call JSON.parse(the-text
) and wrap that call in a try-catch. If the try-catch fails, then you can printthe-text
without trying to read the stream twice.The text was updated successfully, but these errors were encountered: