@ -1,21 +1,23 @@
@@ -1,21 +1,23 @@
import { HttpStatusCode } from "@bitwarden/common/enums" ;
import { Utils } from "@bitwarden/common/platform/misc/utils" ;
import { Account } from "./account" ;
import { OtpMethod , Platform } from "../enums" ;
import {
Account ,
Chunk ,
ClientInfo ,
OobResult ,
OtpResult ,
ParserOptions ,
Session ,
SharedFolder ,
} from "../models" ;
import { Ui } from "../ui" ;
import { BinaryReader } from "./binary-reader" ;
import { Chunk } from "./chunk" ;
import { ClientInfo } from "./client-info" ;
import { CryptoUtils } from "./crypto-utils" ;
import { OobResult } from "./oob-result" ;
import { OtpMethod } from "./otp-method" ;
import { OtpResult } from "./otp-result" ;
import { Parser } from "./parser" ;
import { ParserOptions } from "./parser-options" ;
import { Platform } from "./platform" ;
import { RestClient } from "./rest-client" ;
import { Session } from "./session" ;
import { SharedFolder } from "./shared-folder" ;
import { Ui } from "./ui" ;
const PlatformToUserAgent = new Map < Platform , string > ( [
[ Platform . Desktop , "cli" ] ,
@ -68,7 +70,7 @@ export class Client {
@@ -68,7 +70,7 @@ export class Client {
const reader = new BinaryReader ( blob ) ;
const chunks = this . parser . extractChunks ( reader ) ;
if ( ! this . isComplete ( chunks ) ) {
throw "Blob is truncated or corrupted";
throw new Error ( "Blob is truncated or corrupted") ;
}
return await this . parseAccounts ( chunks , encryptionKey , privateKey , options ) ;
}
@ -236,11 +238,11 @@ export class Client {
@@ -236,11 +238,11 @@ export class Client {
passcode = ui . provideYubikeyPasscode ( ) ;
break ;
default :
throw "Invalid OTP method";
throw new Error ( "Invalid OTP method") ;
}
if ( passcode == OtpResult . cancel ) {
throw "Second factor step is canceled by the user";
throw new Error ( "Second factor step is canceled by the user") ;
}
const response = await this . performSingleLoginRequest (
@ -273,7 +275,7 @@ export class Client {
@@ -273,7 +275,7 @@ export class Client {
) : Promise < Session > {
const answer = this . approveOob ( username , parameters , ui , rest ) ;
if ( answer == OobResult . cancel ) {
throw "Out of band step is canceled by the user";
throw new Error ( "Out of band step is canceled by the user") ;
}
const extraParameters = new Map < string , any > ( ) ;
@ -319,7 +321,7 @@ export class Client {
@@ -319,7 +321,7 @@ export class Client {
private approveOob ( username : string , parameters : Map < string , string > , ui : Ui , rest : RestClient ) {
const method = parameters . get ( "outofbandtype" ) ;
if ( method == null ) {
throw "Out of band method is not specified";
throw new Error ( "Out of band method is not specified") ;
}
switch ( method ) {
case "lastpassauth" :
@ -329,7 +331,7 @@ export class Client {
@@ -329,7 +331,7 @@ export class Client {
case "salesforcehash" :
return ui . approveSalesforceAuth ( ) ;
default :
throw "Out of band method " + method + " is not supported" ;
throw new Error ( "Out of band method " + method + " is not supported" ) ;
}
}
@ -410,7 +412,7 @@ export class Client {
@@ -410,7 +412,7 @@ export class Client {
if ( attr != null ) {
return attr ;
}
throw "Unknown response schema: attribute " + name + " is missing" ;
throw new Error ( "Unknown response schema: attribute " + name + " is missing" ) ;
}
private getOptionalErrorAttribute ( response : Document , name : string ) : string {
@ -505,7 +507,9 @@ export class Client {
@@ -505,7 +507,9 @@ export class Client {
private makeError ( response : Response ) {
// TODO: error parsing
throw "HTTP request to " + response . url + " failed with status " + response . status + "." ;
throw new Error (
"HTTP request to " + response . url + " failed with status " + response . status + "."
) ;
}
private makeLoginError ( response : Document ) : string {