Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix issues

Abhinava2dbacbcef37
diff --git a/apps/photos/src/pages/two-factor/verify/index.tsx b/apps/photos/src/pages/two-factor/verify/index.tsx
index e05fd7d85e..0821069af8 100644
--- a/apps/photos/src/pages/two-factor/verify/index.tsx
+++ b/apps/photos/src/pages/two-factor/verify/index.tsx
@@ -54,13 +54,14 @@ export default function Home() {
InMemoryStore.delete(MS_KEYS.REDIRECT_URL);
router.push(redirectURL ?? PAGES.CREDENTIALS);
} catch (e) {
- if (e instanceof ApiError) {
- if (e.httpStatusCode === HttpStatusCode.NotFound) {
- logoutUser();
- return;
- }
+ if (
+ e instanceof ApiError &&
+ e.httpStatusCode === HttpStatusCode.NotFound
+ ) {
+ logoutUser();
+ } else {
+ throw e;
}
- throw e;
}
};
return (
diff --git a/apps/photos/src/pages/verify/index.tsx b/apps/photos/src/pages/verify/index.tsx
index b41684dac9..9d8dc9ea9c 100644
--- a/apps/photos/src/pages/verify/index.tsx
+++ b/apps/photos/src/pages/verify/index.tsx
@@ -130,8 +130,9 @@ export default function Verify() {
} else if (e?.httpStatusCode === HttpStatusCode.Gone) {
setFieldError(t('EXPIRED_CODE'));
}
+ } else {
+ setFieldError(`${t('UNKNOWN_ERROR')} ${e.message}`);
}
- setFieldError(`${t('UNKNOWN_ERROR')} ${e.message}`);
}
};
diff --git a/apps/photos/src/services/HTTPService.ts b/apps/photos/src/services/HTTPService.ts
index dae21d1161..ff4e7d7401 100644
--- a/apps/photos/src/services/HTTPService.ts
+++ b/apps/photos/src/services/HTTPService.ts
@@ -1,7 +1,7 @@
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { addLogLine } from 'utils/logging';
import { logError } from 'utils/sentry';
-import { ApiError, CustomError, isApiError } from 'utils/error';
+import { ApiError, CustomError, isApiErrorResponse } from 'utils/error';
interface IHTTPHeaders {
[headerKey: string]: any;
@@ -24,49 +24,47 @@ class HTTPService {
const response = error.response as AxiosResponse<
ApiError | any
>;
-
+ let apiError: ApiError;
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
- if (isApiError(response.data)) {
- const apiError = response.data;
+ if (isApiErrorResponse(response.data)) {
+ const responseData = response.data;
logError(error, 'HTTP Service Error', {
url: config.url,
method: config.method,
xRequestId: response.headers['x-request-id'],
httpStatus: response.status,
- errMessage: apiError.message,
- errCode: apiError.errCode,
+ errMessage: responseData.message,
+ errCode: responseData.code,
});
- throw new ApiError(
- apiError.message,
- apiError.errCode,
- response.status,
- response.statusText
+ apiError = new ApiError(
+ responseData.message,
+ responseData.code,
+ response.status
);
} else {
- logError(error, 'HTTP Service Error', {
- url: config.url,
- method: config.method,
- cfRay: response.headers['cf-ray'],
- xRequestId: response.headers['x-request-id'],
- httpStatus: response.status,
- });
if (response.status >= 400 && response.status < 500) {
- throw new ApiError(
+ apiError = new ApiError(
CustomError.CLIENT_ERROR,
'',
- response.status,
- response.statusText
+ response.status
);
} else {
- throw new ApiError(
+ apiError = new ApiError(
CustomError.ServerError,
'',
- response.status,
- response.statusText
+ response.status
);
}
}
+ logError(apiError, 'HTTP Service Error', {
+ url: config.url,
+ method: config.method,
+ cfRay: response.headers['cf-ray'],
+ xRequestId: response.headers['x-request-id'],
+ httpStatus: response.status,
+ });
+ throw apiError;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
diff --git a/apps/photos/src/services/authenticator/authenticatorService.ts b/apps/photos/src/services/authenticator/authenticatorService.ts
index c618e12b21..cb8baf277b 100644
--- a/apps/photos/src/services/authenticator/authenticatorService.ts
+++ b/apps/photos/src/services/authenticator/authenticatorService.ts
@@ -78,13 +78,15 @@ export const getAuthKey = async (): Promise<AuthKey> => {
);
return resp.data;
} catch (e) {
- logError(e, 'Get key failed');
- if (e instanceof ApiError) {
- if (e.httpStatusCode === HttpStatusCode.NotFound) {
- throw Error(CustomError.AUTH_KEY_NOT_FOUND);
- }
+ if (
+ e instanceof ApiError &&
+ e.httpStatusCode === HttpStatusCode.NotFound
+ ) {
+ throw Error(CustomError.AUTH_KEY_NOT_FOUND);
+ } else {
+ logError(e, 'Get key failed');
+ throw e;
}
- throw e;
}
};
diff --git a/apps/photos/src/services/userService.ts b/apps/photos/src/services/userService.ts
index 3c4b764c77..34ba6c373d 100644
--- a/apps/photos/src/services/userService.ts
+++ b/apps/photos/src/services/userService.ts
@@ -224,12 +224,13 @@ export const isTokenValid = async (token: string) => {
return true;
} catch (e) {
logError(e, 'session-validity api call failed');
- if (e instanceof ApiError) {
- if (e.httpStatusCode === HttpStatusCode.Unauthorized) {
- return false;
- } else {
- return true;
- }
+ if (
+ e instanceof ApiError &&
+ e.httpStatusCode === HttpStatusCode.Unauthorized
+ ) {
+ return false;
+ } else {
+ return true;
}
}
};
@@ -729,12 +730,14 @@ export const verifySRPSession = async (
return resp.data as UserVerificationResponse;
} catch (e) {
logError(e, 'verifySRPSession failed');
- if (e instanceof ApiError) {
- if (e.httpStatusCode === HttpStatusCode.Unauthorized) {
- throw Error(CustomError.INCORRECT_PASSWORD);
- }
+ if (
+ e instanceof ApiError &&
+ e.httpStatusCode === HttpStatusCode.Forbidden
+ ) {
+ throw Error(CustomError.INCORRECT_PASSWORD);
+ } else {
+ throw e;
}
- throw e;
}
};
diff --git a/apps/photos/src/utils/error/index.ts b/apps/photos/src/utils/error/index.ts
index 71c7924884..7a109b002c 100644
--- a/apps/photos/src/utils/error/index.ts
+++ b/apps/photos/src/utils/error/index.ts
@@ -1,25 +1,22 @@
import { HttpStatusCode } from 'axios';
+export class ApiErrorResponse {
+ code: string;
+ message: string;
+}
export class ApiError extends Error {
httpStatusCode: number;
- httpStatusText: string;
errCode: string;
- constructor(
- message: string,
- errCode: string,
- httpStatus: number,
- httpStatusText: string
- ) {
+ constructor(message: string, errCode: string, httpStatus: number) {
super(message);
this.name = 'ApiError';
this.errCode = errCode;
this.httpStatusCode = httpStatus;
- this.httpStatusText = httpStatusText;
}
}
-export function isApiError(object: any): object is ApiError {
+export function isApiErrorResponse(object: any): object is ApiErrorResponse {
return object && 'code' in object && 'message' in object;
}
diff --git a/apps/photos/src/utils/sentry/index.ts b/apps/photos/src/utils/sentry/index.ts
index e566309056..43e2a472f0 100644
--- a/apps/photos/src/utils/sentry/index.ts
+++ b/apps/photos/src/utils/sentry/index.ts
@@ -14,17 +14,17 @@ export const logError = async (
const err = errorWithContext(error, msg);
if (!skipAddLogLine) {
if (error instanceof ApiError) {
- addLogLine(`
- error: ${error?.name} ${error?.message} ${error?.stack}
- msg: ${msg} errorCode: ${JSON.stringify(error?.errCode)}
- httpStatusCode: ${JSON.stringify(error?.httpStatusCode)} ${
+ addLogLine(`error: ${error?.name} ${error?.message}
+ msg: ${msg} errorCode: ${JSON.stringify(error?.errCode)}
+ httpStatusCode: ${JSON.stringify(error?.httpStatusCode)} ${
info ? `info: ${JSON.stringify(info)}` : ''
- }`);
+ }
+ ${error?.stack}`);
} else {
addLogLine(
- `error: ${error?.name} ${error?.message} ${
- error?.stack
- } msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ''}`
+ `error: ${error?.name} ${error?.message}
+ msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ''}
+ ${error?.stack}`
);
}
}
@@ -39,6 +39,9 @@ export const logError = async (
addLocalLog(() => `skipping sentry error: ${error?.name}`);
return;
}
+ if (isErrorUnnecessaryForSentry(error)) {
+ return;
+ }
Sentry.captureException(err, {
level: 'info',
@@ -61,3 +64,12 @@ function errorWithContext(originalError: Error, context: string) {
originalError.stack;
return errorWithContext;
}
+
+function isErrorUnnecessaryForSentry(error: any) {
+ if (error?.message?.includes('Network Error')) {
+ return true;
+ } else if (error?.status === 401) {
+ return true;
+ }
+ return false;
+}