|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +import { HttpTransportType } from "./ITransport"; |
| 5 | + |
4 | 6 | /** Error thrown when an HTTP request fails. */
|
5 | 7 | export class HttpError extends Error {
|
6 | 8 | // @ts-ignore: Intentionally unused.
|
@@ -65,3 +67,120 @@ export class AbortError extends Error {
|
65 | 67 | this.__proto__ = trueProto;
|
66 | 68 | }
|
67 | 69 | }
|
| 70 | + |
| 71 | +/** Error thrown when the selected transport is unsupported by the browser. */ |
| 72 | +/** @private */ |
| 73 | +export class UnsupportedTransportError extends Error { |
| 74 | + // @ts-ignore: Intentionally unused. |
| 75 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 76 | + private __proto__: Error; |
| 77 | + |
| 78 | + /** The {@link @microsoft/signalr.HttpTransportType} this error occured on. */ |
| 79 | + public transport: HttpTransportType; |
| 80 | + |
| 81 | + /** The type name of this error. */ |
| 82 | + public errorType: string; |
| 83 | + |
| 84 | + /** Constructs a new instance of {@link @microsoft/signalr.UnsupportedTransportError}. |
| 85 | + * |
| 86 | + * @param {string} message A descriptive error message. |
| 87 | + * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occured on. |
| 88 | + */ |
| 89 | + constructor(message: string, transport: HttpTransportType) { |
| 90 | + const trueProto = new.target.prototype; |
| 91 | + super(message); |
| 92 | + this.transport = transport; |
| 93 | + this.errorType = 'UnsupportedTransportError'; |
| 94 | + |
| 95 | + // Workaround issue in Typescript compiler |
| 96 | + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 |
| 97 | + this.__proto__ = trueProto; |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +/** Error thrown when the selected transport is disabled by the browser. */ |
| 102 | +/** @private */ |
| 103 | +export class DisabledTransportError extends Error { |
| 104 | + // @ts-ignore: Intentionally unused. |
| 105 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 106 | + private __proto__: Error; |
| 107 | + |
| 108 | + /** The {@link @microsoft/signalr.HttpTransportType} this error occured on. */ |
| 109 | + public transport: HttpTransportType; |
| 110 | + |
| 111 | + /** The type name of this error. */ |
| 112 | + public errorType: string; |
| 113 | + |
| 114 | + /** Constructs a new instance of {@link @microsoft/signalr.DisabledTransportError}. |
| 115 | + * |
| 116 | + * @param {string} message A descriptive error message. |
| 117 | + * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occured on. |
| 118 | + */ |
| 119 | + constructor(message: string, transport: HttpTransportType) { |
| 120 | + const trueProto = new.target.prototype; |
| 121 | + super(message); |
| 122 | + this.transport = transport; |
| 123 | + this.errorType = 'DisabledTransportError'; |
| 124 | + |
| 125 | + // Workaround issue in Typescript compiler |
| 126 | + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 |
| 127 | + this.__proto__ = trueProto; |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +/** Error thrown when the selected transport cannot be started. */ |
| 132 | +/** @private */ |
| 133 | +export class FailedToStartTransportError extends Error { |
| 134 | + // @ts-ignore: Intentionally unused. |
| 135 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 136 | + private __proto__: Error; |
| 137 | + |
| 138 | + /** The {@link @microsoft/signalr.HttpTransportType} this error occured on. */ |
| 139 | + public transport: HttpTransportType; |
| 140 | + |
| 141 | + /** The type name of this error. */ |
| 142 | + public errorType: string; |
| 143 | + |
| 144 | + /** Constructs a new instance of {@link @microsoft/signalr.FailedToStartTransportError}. |
| 145 | + * |
| 146 | + * @param {string} message A descriptive error message. |
| 147 | + * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occured on. |
| 148 | + */ |
| 149 | + constructor(message: string, transport: HttpTransportType) { |
| 150 | + const trueProto = new.target.prototype; |
| 151 | + super(message); |
| 152 | + this.transport = transport; |
| 153 | + this.errorType = 'FailedToStartTransportError'; |
| 154 | + |
| 155 | + // Workaround issue in Typescript compiler |
| 156 | + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 |
| 157 | + this.__proto__ = trueProto; |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +/** Error thrown when multiple errors have occured. */ |
| 162 | +/** @private */ |
| 163 | +export class AggregateErrors extends Error { |
| 164 | + // @ts-ignore: Intentionally unused. |
| 165 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 166 | + private __proto__: Error; |
| 167 | + |
| 168 | + /** The collection of errors this error is aggregating. */ |
| 169 | + public innerErrors: Error[]; |
| 170 | + |
| 171 | + /** Constructs a new instance of {@link @microsoft/signalr.AggregateErrors}. |
| 172 | + * |
| 173 | + * @param {string} message A descriptive error message. |
| 174 | + * @param {Error[]} innerErrors The collection of errors this error is aggregating. |
| 175 | + */ |
| 176 | + constructor(message: string, innerErrors: Error[]) { |
| 177 | + const trueProto = new.target.prototype; |
| 178 | + super(message); |
| 179 | + |
| 180 | + this.innerErrors = innerErrors; |
| 181 | + |
| 182 | + // Workaround issue in Typescript compiler |
| 183 | + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 |
| 184 | + this.__proto__ = trueProto; |
| 185 | + } |
| 186 | +} |
0 commit comments