error.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable @typescript-eslint/naming-convention */
  2. /**
  3. * Base error. Due to limitations of typedoc-check and missing documentation
  4. * in lib.es5.d.ts, cannot extend Error directly for RuntimeError.
  5. * @ignore
  6. */
  7. export class BaseError extends Error {
  8. }
  9. // See https://stackoverflow.com/questions/12915412/how-do-i-extend-a-host-object-e-g-error-in-typescript
  10. // and https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
  11. // Polyfill for Object.setPrototypeOf if necessary.
  12. BaseError._setPrototypeOf = Object.setPrototypeOf ||
  13. ((o, proto) => {
  14. o.__proto__ = proto;
  15. return o;
  16. });
  17. /* IMP! DO NOT CHANGE THE NUMBERING OF EXISTING ERROR CODES */
  18. /**
  19. * Error codes for BaseError
  20. */
  21. export const ErrorCodes = {
  22. // Mesh errors 0-999
  23. /** Invalid or empty mesh vertex positions. */
  24. MeshInvalidPositionsError: 0,
  25. // Texture errors 1000-1999
  26. /** Unsupported texture found. */
  27. UnsupportedTextureError: 1000,
  28. // GLTFLoader errors 2000-2999
  29. /** Unexpected magic number found in GLTF file header. */
  30. GLTFLoaderUnexpectedMagicError: 2000,
  31. // SceneLoader errors 3000-3999
  32. /** SceneLoader generic error code. Ideally wraps the inner exception. */
  33. SceneLoaderError: 3000,
  34. // File related errors 4000-4999
  35. /** Load file error */
  36. LoadFileError: 4000,
  37. /** Request file error */
  38. RequestFileError: 4001,
  39. /** Read file error */
  40. ReadFileError: 4002,
  41. };
  42. /**
  43. * Application runtime error
  44. */
  45. export class RuntimeError extends BaseError {
  46. /**
  47. * Creates a new RuntimeError
  48. * @param message defines the message of the error
  49. * @param errorCode the error code
  50. * @param innerError the error that caused the outer error
  51. */
  52. constructor(message, errorCode, innerError) {
  53. super(message);
  54. this.errorCode = errorCode;
  55. this.innerError = innerError;
  56. this.name = "RuntimeError";
  57. BaseError._setPrototypeOf(this, RuntimeError.prototype);
  58. }
  59. }
  60. //# sourceMappingURL=error.js.map