Skip to content

Commit

Permalink
Better log message
Browse files Browse the repository at this point in the history
  • Loading branch information
codler committed Oct 6, 2019
1 parent 37b104e commit ff0eab2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ async function getAuthenticationSessionsUsercredentials(

const responseJson: ResponseAuthenticationSessionsUsercredentials = await response.json();
if (typeof responseJson.twoFactorLogin === "undefined") {
console.error("Failed to authenticate", responseJson);
console.error(
"Request usercredentials: Failed to authenticate",
responseJson
);
throw "Failed to authenticate";
}
if (responseJson.twoFactorLogin.method !== "TOTP") {
Expand Down Expand Up @@ -179,6 +182,10 @@ async function getAuthenticationSessionsTotp(
}
});

if (response.status === 401) {
throw new Error("Unauthorized Totp");
}

const securityToken = response.headers.get("x-securitytoken");
if (!securityToken) {
throw "Error getting security token";
Expand Down
8 changes: 6 additions & 2 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ async function init() {
avanza.session = require("./session.json");
} catch {}
if (!avanza.isAuthenticated) {
await avanza.authenticate(require("./credential.json"));
try {
await avanza.authenticate(require("./credential.json"));
} catch (e) {
console.log("Test: Catch:", e);
}
}

if (avanza.isAuthenticated) {
Expand All @@ -25,6 +29,6 @@ async function init() {
const ava = await avanza.getOrderbooks(orderbookIds);
console.log(ava);
} else {
console.log("Failed to authenticate");
console.log("Test: Failed to authenticate");
}
}

0 comments on commit ff0eab2

Please sign in to comment.