diff --git a/src/api.js b/src/api.js index 0260c25..bbb5e15 100644 --- a/src/api.js +++ b/src/api.js @@ -323,6 +323,9 @@ export async function getTOTPKeys(baseMount) { } }); return fetch(request).then(response => { + if (response.status == 404) { + throw DoesNotExistError; + } return response.json(); }).then(data => { return data.data.keys; diff --git a/src/main.js b/src/main.js index 91640ba..78a28f7 100644 --- a/src/main.js +++ b/src/main.js @@ -15,6 +15,7 @@ import { } from "./pageUtils.js"; import { PageState } from "./PageState.js"; import { makeElement } from "./htmlUtils.js"; +import { getSealStatus } from './api.js'; import { HomePage, @@ -36,8 +37,6 @@ import { PwGenPage, } from "./pages"; -import { getSealStatus } from './api.js'; - const pages = { HOME: new HomePage(), TOTP: new TOTPViewPage(), diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index 2141ad9..3de4b47 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -1,5 +1,5 @@ import { Page } from "../../types/Page.js"; -import { getTOTPKeys, getTOTPCode } from "../../api.js"; +import { getTOTPKeys, getTOTPCode, DoesNotExistError } from "../../api.js"; import { setTitleElement, setPageContent, changePage } from "../../pageUtils.js"; import { CopyableInputBox } from "../../elements/CopyableInputBox.js"; import { makeElement } from "../../htmlUtils.js"; @@ -43,7 +43,15 @@ export class TOTPViewPage extends Page { this.refreshers.push(setInterval(totpRefresher, 3000, totpKeyName, totpListElement)); }, this); document.getElementById("loadingText").remove(); + }).catch(e => { + if (e == DoesNotExistError) { + let loadingText = document.getElementById("loadingText"); + loadingText.innerText = "You seem to have no TOTP codes here, would you like to create one?"; + } else { + setErrorText(e.message); + } }); + } cleanup() {