Skip to content

Impossible to catch and format errors #305

@DanielHreben

Description

@DanielHreben

Library throws errors of generic TypeError without any additional information attached to them. It makes it almost impossible to distinguish them from TypeErrors thrown by any other piece of code. The only option is to try to parse error messages, which is not convenient and unreliable, cuz they seem like not something that is part of the library API contract. Could you please add custom error class like this?

export class JSONTypeError extends TypeError { // Custom class makes it possible to differentiate errors thrown by this library
  constructor(message) {
    super(message)
    this.code = 'FAILED_TO_PARSE_JSON' // Optionally, may make sense to attach some sort of error code in order to  differentiate it without using `instanceof` operator
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions