Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: add a property #3

Open
basz opened this issue Jul 24, 2018 · 1 comment
Open

Q: add a property #3

basz opened this issue Jul 24, 2018 · 1 comment

Comments

@basz
Copy link

basz commented Jul 24, 2018

Hi,

I'm trying to add an option to some Errors but looking at your code the options are not stored inside the instance.

Also, the 'ember way' of using reopen does not work as these errors are not an ember object.

MaintenanceError.reopen({
  useRouter: true, /* would navigate away from the UI where the issue happened */
  useNotification: true, /* use a notification service */
});

So my question is a JS one. How would I add a property to an error definition?

@basz
Copy link
Author

basz commented Jul 24, 2018

To answer my own question, something this seems to work

const MaintenanceError = defineError({
  name: 'MaintenanceError',
  message: 'Down for maintenance.'
});

MaintenanceError.prototype.useRouter = true;
MaintenanceError.prototype.useNotification = false;

MaintenanceError.prototype.withNotification = function() {
  this.useRouter = false;
  this.useNotification = true;

  return this;
};

MaintenanceError.prototype.withRouter = function() {
  this.useRouter = true;
  this.useNotification = false;

  return this;
};

export default MaintenanceError;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant