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

Feature request: add InvalidPatch and PatchApplyError classes to TypeScript export #41

Open
Kinrany opened this issue Mar 13, 2021 · 2 comments

Comments

@Kinrany
Copy link

Kinrany commented Mar 13, 2021

Currently InvalidPatch and PatchApplyError are being exported as interfaces, i.e. static only.

Classes are useful at runtime for distinguishing between errors.

Workaround:

import { apply_patch, InvalidPatch, PatchApplyError } from 'jsonpatch';

declare module 'jsonpatch' {
  export class InvalidPatch extends Error {}
  export class PatchApplyError extends Error {}
}

try {
  apply_patch(document, patch);
}
catch (e: unknown) {
  if (e instanceof InvalidPatch) {
    console.error('Invalid patch format');
  }
}
@JoshuaWise
Copy link

I also need this.

bennycode added a commit to bennycode/jsonpatch.js that referenced this issue Jul 22, 2024
@bennycode
Copy link
Contributor

I made a PR for this: #41

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

3 participants