D
D
Denis11112018-09-13 19:45:35
JavaScript
Denis1111, 2018-09-13 19:45:35

How can this code be rewritten in ES6?

function AuthError(message) {
  Error.apply(this, arguments);
  Error.captureStackTrace(this, AuthError);

  this.message = message;
}

util.inherits(AuthError, Error);

AuthError.prototype.name = 'AuthError';

exports.AuthError = AuthError;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2018-09-14
@Denis1111

export class AuthError extends Error {
  constructor(message) {
    super(...arguments);
    Error.captureStackTrace(this, AuthError);
    this.message = message;
  }

  get name() {
    return 'AuthError';
  }
}

A
Anton fon Faust, 2018-09-13
@bubandos

Weird code in some places... and not all of it.
But most likely like this:
import { Error } from "path/to/class/Error"
class AuthError extends Error {
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question