Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove custom errors indirection

Manav Rathi8a00f1b85fe0
diff --git a/web/apps/payments/src/pages/index.tsx b/web/apps/payments/src/pages/index.tsx
index 64c8b96a7a..96d22d5ad3 100644
--- a/web/apps/payments/src/pages/index.tsx
+++ b/web/apps/payments/src/pages/index.tsx
@@ -2,27 +2,17 @@ import { Container } from "components/Container";
import { Spinner } from "components/Spinner";
import * as React from "react";
import { parseAndHandleRequest } from "services/billingService";
-import { CUSTOM_ERROR } from "utils/error";
import constants from "utils/strings";
export default function Home() {
- const [errorMessageView, setErrorMessageView] = React.useState(false);
- const [loading, setLoading] = React.useState(false);
+ const [failed, setFailed] = React.useState(false);
React.useEffect(() => {
async function main() {
try {
- setLoading(true);
await parseAndHandleRequest();
- } catch (e: unknown) {
- if (
- e instanceof Error &&
- e.message === CUSTOM_ERROR.DIRECT_OPEN_WITH_NO_QUERY_PARAMS
- ) {
- window.location.href = "https://ente.io";
- } else {
- setErrorMessageView(true);
- }
+ } catch {
+ setFailed(true);
}
}
// TODO: audit
@@ -32,11 +22,7 @@ export default function Home() {
return (
<Container>
- {errorMessageView ? (
- <div>{constants.SOMETHING_WENT_WRONG}</div>
- ) : (
- loading && <Spinner />
- )}
+ {failed ? constants.SOMETHING_WENT_WRONG : <Spinner />}
</Container>
);
}
diff --git a/web/apps/payments/src/services/billingService.ts b/web/apps/payments/src/services/billingService.ts
index 9224129d3d..7668b591c8 100644
--- a/web/apps/payments/src/services/billingService.ts
+++ b/web/apps/payments/src/services/billingService.ts
@@ -7,7 +7,6 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { loadStripe } from "@stripe/stripe-js";
-import { CUSTOM_ERROR } from "utils/error";
import { logError } from "utils/log";
import HTTPService from "./HTTPService";
@@ -88,9 +87,15 @@ export async function parseAndHandleRequest() {
const action = urlParams.get("action");
const redirectURL = urlParams.get("redirectURL");
if (!action && !paymentToken && !productID && !redirectURL) {
- throw Error(CUSTOM_ERROR.DIRECT_OPEN_WITH_NO_QUERY_PARAMS);
+ // Maybe someone attempted to directly open this page in their
+ // browser. Not much we can do, just redirect them to the main site.
+ console.log(
+ "None of the required query parameters were supplied, redirecting to the ente.io",
+ );
+ redirectHome();
+ return;
} else if (!action || !paymentToken || !productID || !redirectURL) {
- throw Error(CUSTOM_ERROR.MISSING_REQUIRED_QUERY_PARAM);
+ throw Error("Required query parameter was not provided");
}
switch (action) {
case PaymentActionType.Buy:
@@ -100,13 +105,11 @@ export async function parseAndHandleRequest() {
await updateSubscription(productID, paymentToken, redirectURL);
break;
default:
- throw Error(CUSTOM_ERROR.INVALID_ACTION);
+ throw Error(`Unsupported action ${action}`);
}
} catch (e: any) {
console.error("Error: ", JSON.stringify(e));
- if (e.message !== CUSTOM_ERROR.DIRECT_OPEN_WITH_NO_QUERY_PARAMS) {
- logError(e);
- }
+ logError(e);
throw e;
}
}
@@ -285,3 +288,7 @@ function redirectToApp(redirectURL: string, status: string, reason?: string) {
}
window.location.href = completePath;
}
+
+const redirectHome = () => {
+ window.location.href = "https://ente.io";
+};
diff --git a/web/apps/payments/src/utils/error.ts b/web/apps/payments/src/utils/error.ts
deleted file mode 100644
index c38b2bf6cd..0000000000
--- a/web/apps/payments/src/utils/error.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export const CUSTOM_ERROR = {
- DIRECT_OPEN_WITH_NO_QUERY_PARAMS: "direct open with no query params",
- MISSING_REQUIRED_QUERY_PARAM: "missing required query param",
- INVALID_ACTION: "invalid action",
-};