errors.js 882 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const OError = require('@overleaf/o-error')
  2. class UnprocessableError extends OError {}
  3. class ApplyError extends UnprocessableError {
  4. constructor(message, operation, operand) {
  5. super(message, { operation, operand })
  6. this.operation = operation
  7. this.operand = operand
  8. }
  9. }
  10. class InvalidInsertionError extends UnprocessableError {
  11. constructor(str, operation) {
  12. super('inserted text contains non BMP characters', { str, operation })
  13. this.str = str
  14. this.operation = operation
  15. }
  16. }
  17. class TooLongError extends UnprocessableError {
  18. constructor(operation, resultLength) {
  19. super(`resulting string would be too long: ${resultLength}`, {
  20. operation,
  21. resultLength,
  22. })
  23. this.operation = operation
  24. this.resultLength = resultLength
  25. }
  26. }
  27. module.exports = {
  28. UnprocessableError,
  29. ApplyError,
  30. InvalidInsertionError,
  31. TooLongError,
  32. }