From 88547656ce88786e2dcac8e8e0e78045b67e8e16 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Thu, 1 Feb 2018 08:39:15 -0800 Subject: [PATCH] fix(UserSession): throw ArcGISAuthError instead of Error when unable to refresh a token AFFECTS PACKAGES: @esri/arcgis-rest-auth ISSUES CLOSED: #56 --- packages/arcgis-rest-auth/src/UserSession.ts | 2 +- packages/arcgis-rest-auth/test/UserSession.test.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/arcgis-rest-auth/src/UserSession.ts b/packages/arcgis-rest-auth/src/UserSession.ts index 0eb57a52c7..9bbf2844e8 100644 --- a/packages/arcgis-rest-auth/src/UserSession.ts +++ b/packages/arcgis-rest-auth/src/UserSession.ts @@ -522,7 +522,7 @@ export class UserSession implements IAuthenticationManager { return this.refreshWithRefreshToken(); } - return Promise.reject(new Error("Unable to refresh token.")); + return Promise.reject(new ArcGISAuthError("Unable to refresh token.")); } /** diff --git a/packages/arcgis-rest-auth/test/UserSession.test.ts b/packages/arcgis-rest-auth/test/UserSession.test.ts index 7fafd421a6..a52ffafb31 100644 --- a/packages/arcgis-rest-auth/test/UserSession.test.ts +++ b/packages/arcgis-rest-auth/test/UserSession.test.ts @@ -1,5 +1,9 @@ import { UserSession, IFetchTokenResponse } from "../src/index"; -import { ArcGISRequestError, ErrorTypes } from "@esri/arcgis-rest-request"; +import { + ArcGISRequestError, + ArcGISAuthError, + ErrorTypes +} from "@esri/arcgis-rest-request"; import * as fetchMock from "fetch-mock"; import { YESTERDAY, TOMORROW } from "./utils"; @@ -350,6 +354,8 @@ describe("UserSession", () => { }); session.refreshSession().catch(e => { + expect(e instanceof ArcGISAuthError).toBeTruthy(); + expect(e.name).toBe("ArcGISAuthError"); expect(e.message).toBe("Unable to refresh token."); done(); });