-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove rollbar service - ErrorService now passed in as a startOption, configuration passed to init function called on the service.
- Loading branch information
Showing
8 changed files
with
82 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,14 @@ | ||
import TerriaError from "../../Core/TerriaError"; | ||
|
||
import { ConfigParameters } from "../Terria"; | ||
export interface ErrorServiceOptions { | ||
provider: string; | ||
provider?: string; | ||
configuration: any; | ||
} | ||
|
||
/** | ||
* The interface that all valid error service providers must implement. | ||
*/ | ||
export type ErrorServiceProvider = { | ||
error(error: string | Error | TerriaError): void; | ||
}; | ||
|
||
/** | ||
* Asynchronously loads and returns an error service provider instance for the given options. | ||
*/ | ||
export async function initializeErrorServiceProvider( | ||
options?: ErrorServiceOptions | ||
): Promise<ErrorServiceProvider> { | ||
const provider = options?.provider; | ||
const configuration = options?.configuration; | ||
|
||
if (provider === "rollbar") { | ||
const rollbarModule = await import("./RollbarErrorServiceProvider"); | ||
const rollbarProvider = new rollbarModule.default(configuration); | ||
return rollbarProvider; | ||
} else { | ||
throw new Error(`Unknown error service provider: ${provider}`); | ||
} | ||
export interface ErrorServiceProvider { | ||
init: (config: ConfigParameters) => void; | ||
error: (error: string | Error | TerriaError) => void; | ||
} |
39 changes: 0 additions & 39 deletions
39
lib/Models/ErrorServiceProviders/RollbarErrorServiceProvider.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,59 @@ | ||
import { initializeErrorServiceProvider } from "../../lib/Models/ErrorServiceProviders/ErrorService"; | ||
import RollbarErrorServiceProvider from "../../lib/Models/ErrorServiceProviders/RollbarErrorServiceProvider"; | ||
import TerriaError from "../../lib/Core/TerriaError"; | ||
import { ErrorServiceProvider } from "../../lib/Models/ErrorServiceProviders/ErrorService"; | ||
import StubErrorServiceProvider from "../../lib/Models/ErrorServiceProviders/StubErrorServiceProvider"; | ||
import Terria from "../../lib/Models/Terria"; | ||
|
||
describe("initializeErrorServiceProvider", function () { | ||
it("can initialize RollbarErrorServiceProvider", async function () { | ||
const errorService = await initializeErrorServiceProvider({ | ||
provider: "rollbar", | ||
configuration: {} | ||
describe("ErrorService", function () { | ||
let mockErrorServiceProvider: ErrorServiceProvider; | ||
let terria: Terria; | ||
|
||
beforeAll(() => { | ||
jasmine.Ajax.stubRequest(/.*/).andError({}); | ||
jasmine.Ajax.stubRequest(/.*(serverconfig|proxyabledomains).*/).andReturn({ | ||
responseText: JSON.stringify({ foo: "bar" }) | ||
}); | ||
jasmine.Ajax.stubRequest("test-config.json").andReturn({ | ||
responseText: JSON.stringify({ config: true }) | ||
}); | ||
expect(errorService instanceof RollbarErrorServiceProvider).toBe(true); | ||
mockErrorServiceProvider = { | ||
init: () => {}, | ||
error: () => {} | ||
}; | ||
}); | ||
|
||
it("throws an error when an invalid provider type is given", async function () { | ||
let error; | ||
try { | ||
await initializeErrorServiceProvider({ | ||
provider: "foo", | ||
configuration: undefined | ||
}); | ||
} catch (e: any) { | ||
error = e; | ||
} | ||
expect(error.message).toBe(`Unknown error service provider: foo`); | ||
beforeEach(() => { | ||
terria = new Terria({ | ||
appBaseHref: "/", | ||
baseUrl: "./" | ||
}); | ||
}); | ||
|
||
it("Initializes an error service, passing in config", async function () { | ||
const initSpy = spyOn(mockErrorServiceProvider, "init"); | ||
await terria.start({ | ||
configUrl: "test-config.json", | ||
errorService: mockErrorServiceProvider | ||
}); | ||
expect(initSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Gets called with error", async function () { | ||
const errorSpy = spyOn(mockErrorServiceProvider, "error").and.callThrough(); | ||
await terria.start({ | ||
configUrl: "test-config.json", | ||
errorService: mockErrorServiceProvider | ||
}); | ||
const error = new TerriaError({ | ||
message: "test error" | ||
}); | ||
terria.raiseErrorToUser(error); | ||
expect(errorSpy).toHaveBeenCalledWith(error); | ||
}); | ||
|
||
it("Falls back to stub provider", () => { | ||
terria.start({ | ||
configUrl: "test-config.json" | ||
}); | ||
expect(terria.errorService).toEqual(jasmine.any(StubErrorServiceProvider)); | ||
}); | ||
}); |