Skip to content

Commit

Permalink
feat: introduce ErrorTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Jan 17, 2022
1 parent b8fa443 commit 23f8e33
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export class ErrorResponse extends Error {
state?: unknown;
}

// @public
export class ErrorTimeout extends Error {
constructor(message?: string);
readonly name: string;
}

// @public (undocumented)
export type ExtraSigninRequestArgs = Pick<CreateSigninRequestArgs, "extraQueryParams" | "extraTokenParams" | "state">;

Expand Down
16 changes: 16 additions & 0 deletions src/errors/ErrorTimeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2021 AuthTS Contributors
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

/**
* Error class thrown in case of network timeouts (e.g IFrame time out).
*
* @public
*/
export class ErrorTimeout extends Error {
/** Marker to detect class: "ErrorTimeout" */
public readonly name: string = "ErrorTimeout";

public constructor(message?: string) {
super(message);
}
}
3 changes: 2 additions & 1 deletion src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./ErrorResponse";
export * from "./ErrorResponse";
export * from "./ErrorTimeout";
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

export { ErrorResponse } from "./errors";
export { ErrorResponse, ErrorTimeout } from "./errors";
export type { IFrameWindowParams, PopupWindowParams, RedirectParams } from "./navigators";
export { Log, Logger } from "./utils";
export type { ILogger, PopupWindowFeatures } from "./utils";
Expand Down
3 changes: 2 additions & 1 deletion src/navigators/IFrameWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Logger } from "../utils";
import { ErrorTimeout } from "../errors";
import type { NavigateParams, NavigateResponse } from "./IWindow";
import { AbstractChildWindow } from "./AbstractChildWindow";

Expand Down Expand Up @@ -45,7 +46,7 @@ export class IFrameWindow extends AbstractChildWindow {

public async navigate(params: NavigateParams): Promise<NavigateResponse> {
this._logger.debug("navigate: Using timeout of:", this._timeoutInSeconds);
const timer = setTimeout(() => this._abort.raise(new Error("IFrame timed out without a response")), this._timeoutInSeconds * 1000);
const timer = setTimeout(() => this._abort.raise(new ErrorTimeout("IFrame timed out without a response")), this._timeoutInSeconds * 1000);
this._disposeHandlers.add(() => clearTimeout(timer));

return await super.navigate(params);
Expand Down

0 comments on commit 23f8e33

Please sign in to comment.