Skip to content

Catch with errors.StatusCodeError doesn't work if a generic exception is thrown #52

@articice

Description

@articice

When using native promises .catch() with error filter, if the function with received body throws an error, the constructor of the error itself throws another error.

TypeError: Cannot set property 'name' of undefined
at StatusCodeError (/home/user/project/node_modules/request-promise-core/lib/errors.js:24:15)

Using this require syntax

const request = require('request-promise-native');
const errors = require('request-promise-native/errors');

consider the following snippet, when the REST API returns status='error':

return request(options)
      .then((reply) => {
        if (reply.status === 'ok') {
          return (reply.data.user.email === user.email);
        } else {
          throw new Error(reply.message || 'Authentication service error');
        }
      }).catch(errors.StatusCodeError, err => {
        if (err.statusCode === 401) {
          console.error('AuthService rejected our authentication settings');
        } else throw err;
      });

NodeJS: 12.8.0
npm: 6.10.2

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