Skip to content

Throw error when reading json response fails #1020

@8ctavio

Description

@8ctavio

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions