In some functions, errors thrown by the expression response?.clone.json() are supressed and the response object is returned instead. I'm not sure if this is done because some action should always be taken with the response object in case it can't be cloned or its response can't be parsed as json, but I currently handle the response of this functions in the following way:
const result = await nile.fn()
if (result instanceof Response) {
// Create error object with result and forward to error handler.
}
This could be done automatically if an error was thrown instead. Perhaps it is a better option to throw in case of an error, and users can catch if needed. The response object itself could be thrown, but a custom Error object could also be created.
For reference, this are the places where response objects are returned upon catching an error:
In some functions, errors thrown by the expression
response?.clone.json()are supressed and the response object is returned instead. I'm not sure if this is done because some action should always be taken with the response object in case it can't be cloned or its response can't be parsed as json, but I currently handle the response of this functions in the following way:This could be done automatically if an error was thrown instead. Perhaps it is a better option to throw in case of an error, and users can catch if needed. The response object itself could be thrown, but a custom
Errorobject could also be created.For reference, this are the places where response objects are returned upon catching an error: