diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts index 34621586ed..9650fe7d28 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts @@ -1,3 +1,5 @@ +import { HttpError } from "./HttpError" + export interface IHttpClient { get(url: string, headers?: Map): Promise; options(url: string, headers?: Map): Promise; @@ -22,6 +24,7 @@ export class HttpClient implements IHttpClient { let xhr = new XMLHttpRequest(); xhr.open(method, url, true); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); if (headers) { headers.forEach((value, header) => xhr.setRequestHeader(header, value)); @@ -33,19 +36,13 @@ export class HttpClient implements IHttpClient { resolve(xhr.response); } else { - reject({ - status: xhr.status, - statusText: xhr.statusText - }); + reject(new HttpError(xhr.statusText, xhr.status)); } }; xhr.onerror = () => { - reject({ - status: xhr.status, - statusText: xhr.statusText - }); - }; + reject(new HttpError(xhr.statusText, xhr.status)); + } }); } } \ No newline at end of file diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpError.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpError.ts new file mode 100644 index 0000000000..e8c04c3e79 --- /dev/null +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpError.ts @@ -0,0 +1,7 @@ +export class HttpError extends Error { + statusCode: number; + constructor(errorMessage: string, statusCode: number) { + super(errorMessage); + this.statusCode = statusCode; + } +} \ No newline at end of file