Errors.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. import { HttpTransportType } from "./ITransport";
  4. /** Error thrown when an HTTP request fails. */
  5. export class HttpError extends Error {
  6. // @ts-ignore: Intentionally unused.
  7. // eslint-disable-next-line @typescript-eslint/naming-convention
  8. private __proto__: Error;
  9. /** The HTTP status code represented by this error. */
  10. public statusCode: number;
  11. /** Constructs a new instance of {@link @microsoft/signalr.HttpError}.
  12. *
  13. * @param {string} errorMessage A descriptive error message.
  14. * @param {number} statusCode The HTTP status code represented by this error.
  15. */
  16. constructor(errorMessage: string, statusCode: number) {
  17. const trueProto = new.target.prototype;
  18. super(`${errorMessage}: Status code '${statusCode}'`);
  19. this.statusCode = statusCode;
  20. // Workaround issue in Typescript compiler
  21. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  22. this.__proto__ = trueProto;
  23. }
  24. }
  25. /** Error thrown when a timeout elapses. */
  26. export class TimeoutError extends Error {
  27. // @ts-ignore: Intentionally unused.
  28. // eslint-disable-next-line @typescript-eslint/naming-convention
  29. private __proto__: Error;
  30. /** Constructs a new instance of {@link @microsoft/signalr.TimeoutError}.
  31. *
  32. * @param {string} errorMessage A descriptive error message.
  33. */
  34. constructor(errorMessage: string = "A timeout occurred.") {
  35. const trueProto = new.target.prototype;
  36. super(errorMessage);
  37. // Workaround issue in Typescript compiler
  38. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  39. this.__proto__ = trueProto;
  40. }
  41. }
  42. /** Error thrown when an action is aborted. */
  43. export class AbortError extends Error {
  44. // @ts-ignore: Intentionally unused.
  45. // eslint-disable-next-line @typescript-eslint/naming-convention
  46. private __proto__: Error;
  47. /** Constructs a new instance of {@link AbortError}.
  48. *
  49. * @param {string} errorMessage A descriptive error message.
  50. */
  51. constructor(errorMessage: string = "An abort occurred.") {
  52. const trueProto = new.target.prototype;
  53. super(errorMessage);
  54. // Workaround issue in Typescript compiler
  55. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  56. this.__proto__ = trueProto;
  57. }
  58. }
  59. /** Error thrown when the selected transport is unsupported by the browser. */
  60. /** @private */
  61. export class UnsupportedTransportError extends Error {
  62. // @ts-ignore: Intentionally unused.
  63. // eslint-disable-next-line @typescript-eslint/naming-convention
  64. private __proto__: Error;
  65. /** The {@link @microsoft/signalr.HttpTransportType} this error occurred on. */
  66. public transport: HttpTransportType;
  67. /** The type name of this error. */
  68. public errorType: string;
  69. /** Constructs a new instance of {@link @microsoft/signalr.UnsupportedTransportError}.
  70. *
  71. * @param {string} message A descriptive error message.
  72. * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
  73. */
  74. constructor(message: string, transport: HttpTransportType) {
  75. const trueProto = new.target.prototype;
  76. super(message);
  77. this.transport = transport;
  78. this.errorType = 'UnsupportedTransportError';
  79. // Workaround issue in Typescript compiler
  80. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  81. this.__proto__ = trueProto;
  82. }
  83. }
  84. /** Error thrown when the selected transport is disabled by the browser. */
  85. /** @private */
  86. export class DisabledTransportError extends Error {
  87. // @ts-ignore: Intentionally unused.
  88. // eslint-disable-next-line @typescript-eslint/naming-convention
  89. private __proto__: Error;
  90. /** The {@link @microsoft/signalr.HttpTransportType} this error occurred on. */
  91. public transport: HttpTransportType;
  92. /** The type name of this error. */
  93. public errorType: string;
  94. /** Constructs a new instance of {@link @microsoft/signalr.DisabledTransportError}.
  95. *
  96. * @param {string} message A descriptive error message.
  97. * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
  98. */
  99. constructor(message: string, transport: HttpTransportType) {
  100. const trueProto = new.target.prototype;
  101. super(message);
  102. this.transport = transport;
  103. this.errorType = 'DisabledTransportError';
  104. // Workaround issue in Typescript compiler
  105. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  106. this.__proto__ = trueProto;
  107. }
  108. }
  109. /** Error thrown when the selected transport cannot be started. */
  110. /** @private */
  111. export class FailedToStartTransportError extends Error {
  112. // @ts-ignore: Intentionally unused.
  113. // eslint-disable-next-line @typescript-eslint/naming-convention
  114. private __proto__: Error;
  115. /** The {@link @microsoft/signalr.HttpTransportType} this error occurred on. */
  116. public transport: HttpTransportType;
  117. /** The type name of this error. */
  118. public errorType: string;
  119. /** Constructs a new instance of {@link @microsoft/signalr.FailedToStartTransportError}.
  120. *
  121. * @param {string} message A descriptive error message.
  122. * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
  123. */
  124. constructor(message: string, transport: HttpTransportType) {
  125. const trueProto = new.target.prototype;
  126. super(message);
  127. this.transport = transport;
  128. this.errorType = 'FailedToStartTransportError';
  129. // Workaround issue in Typescript compiler
  130. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  131. this.__proto__ = trueProto;
  132. }
  133. }
  134. /** Error thrown when the negotiation with the server failed to complete. */
  135. /** @private */
  136. export class FailedToNegotiateWithServerError extends Error {
  137. // @ts-ignore: Intentionally unused.
  138. // eslint-disable-next-line @typescript-eslint/naming-convention
  139. private __proto__: Error;
  140. /** The type name of this error. */
  141. public errorType: string;
  142. /** Constructs a new instance of {@link @microsoft/signalr.FailedToNegotiateWithServerError}.
  143. *
  144. * @param {string} message A descriptive error message.
  145. */
  146. constructor(message: string) {
  147. const trueProto = new.target.prototype;
  148. super(message);
  149. this.errorType = 'FailedToNegotiateWithServerError';
  150. // Workaround issue in Typescript compiler
  151. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  152. this.__proto__ = trueProto;
  153. }
  154. }
  155. /** Error thrown when multiple errors have occurred. */
  156. /** @private */
  157. export class AggregateErrors extends Error {
  158. // @ts-ignore: Intentionally unused.
  159. // eslint-disable-next-line @typescript-eslint/naming-convention
  160. private __proto__: Error;
  161. /** The collection of errors this error is aggregating. */
  162. public innerErrors: Error[];
  163. /** Constructs a new instance of {@link @microsoft/signalr.AggregateErrors}.
  164. *
  165. * @param {string} message A descriptive error message.
  166. * @param {Error[]} innerErrors The collection of errors this error is aggregating.
  167. */
  168. constructor(message: string, innerErrors: Error[]) {
  169. const trueProto = new.target.prototype;
  170. super(message);
  171. this.innerErrors = innerErrors;
  172. // Workaround issue in Typescript compiler
  173. // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
  174. this.__proto__ = trueProto;
  175. }
  176. }