Skip to content

The second argument "Error" overwrites the first argument "status" #58

@Nicolas-yonedA

Description

@Nicolas-yonedA

I am sorry if I had written rude things because I am poor at English.

When I specified Error as the second argument, there was a key like status or statusCode, so the status code of the first argument was overwritten.

Error is like this.

{ MessageRejected: Email address is not verified.....
    message: 'Rejected',
    code: 'ClientError',
    statusCode: 400}
    

And, I written the following code.

try {
    ....
} catch (e) {
    throw createError(500, e, { errors: [{ msg: 'sending mail was failed' }] })
}

In the case of the above error, the first argument is ignored and the return value of status is forced to 400.
And I return the status of the Error to the client, as the status code of the response.

This is caused by the following code.

  for (var i = 0; i < arguments.length; i++) {
    var arg = arguments[i]
    if (arg instanceof Error) {
      err = arg
      status = err.status || err.statusCode || status

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think it's strange that status was changed by the first argument , but it will changed again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions