mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[EC-598] feat: improve error handling
This commit is contained in:
@@ -54,9 +54,30 @@ export interface CredentialAssertResult {
|
|||||||
userHandle: string;
|
userHandle: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RequestAbortedError extends Error {
|
export class Fido2Error extends Error {
|
||||||
constructor(readonly fallbackRequested = false) {
|
constructor(message: string, readonly fallbackRequested = false) {
|
||||||
super("Fido2 request was aborted");
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RequestAbortedError extends Fido2Error {
|
||||||
|
constructor(fallbackRequested = false) {
|
||||||
|
super("Fido2 request was aborted", fallbackRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NoCredentialFoundError extends Fido2Error {
|
||||||
|
constructor() {
|
||||||
|
super("No valid credential found", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OriginMismatchError extends Fido2Error {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"Authentication requests must originate from the same source that created the credential.",
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
CredentialRegistrationParams,
|
CredentialRegistrationParams,
|
||||||
CredentialRegistrationResult,
|
CredentialRegistrationResult,
|
||||||
Fido2Service as Fido2ServiceAbstraction,
|
Fido2Service as Fido2ServiceAbstraction,
|
||||||
|
NoCredentialFoundError,
|
||||||
|
OriginMismatchError,
|
||||||
} from "../../abstractions/fido2/fido2.service.abstraction";
|
} from "../../abstractions/fido2/fido2.service.abstraction";
|
||||||
import { Utils } from "../../misc/utils";
|
import { Utils } from "../../misc/utils";
|
||||||
|
|
||||||
@@ -118,11 +120,11 @@ export class Fido2Service implements Fido2ServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (credential === undefined) {
|
if (credential === undefined) {
|
||||||
throw new Error("No valid credentials found");
|
throw new NoCredentialFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credential.origin !== params.origin) {
|
if (credential.origin !== params.origin) {
|
||||||
throw new Error("Not allowed: Origin mismatch");
|
throw new OriginMismatchError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
|
|||||||
Reference in New Issue
Block a user