π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update HTTPService to throw APIError when server sends non 2xx response
Abhinavf1504272e69e
diff --git a/apps/photos/src/services/HTTPService.ts b/apps/photos/src/services/HTTPService.tsindex a2c9d5a460..63f53bdc87 100644--- a/apps/photos/src/services/HTTPService.ts+++ b/apps/photos/src/services/HTTPService.ts@@ -35,9 +35,14 @@ class HTTPService {xRequestId: response.headers['x-request-id'],httpStatusCode: response.status,errMessage: apiError.message,- errCode: apiError.code,+ errCode: apiError.errCode,});- return Promise.reject(response.data);+ throw new ApiError(+ apiError.message,+ apiError.errCode,+ response.status,+ response.statusText+ );} else {logError(error, 'HTTP Service Error', {url: config.url,@@ -46,7 +51,21 @@ class HTTPService {xRequestId: response.headers['x-request-id'],status: response.status,});- return Promise.reject(response);+ if (response.status >= 400 && response.status < 500) {+ throw new ApiError(+ response.statusText,+ 'Client Error',+ response.status,+ response.statusText+ );+ } else {+ throw new ApiError(+ response.statusText,+ 'Server Error',+ response.status,+ response.statusText+ );+ }}} else if (error.request) {// The request was made but no response was receiveddiff --git a/apps/photos/src/utils/error/index.ts b/apps/photos/src/utils/error/index.tsindex 64513d464f..ffa6c634d4 100644--- a/apps/photos/src/utils/error/index.ts+++ b/apps/photos/src/utils/error/index.ts@@ -1,6 +1,20 @@-export interface ApiError {- code: string;- message: string;+export class ApiError extends Error {+ httpStatus: number;+ httpStatusText: string;+ errCode: string;++ constructor(+ message: string,+ errCode: string,+ httpStatus: number,+ httpStatusText: string+ ) {+ super(message);+ this.name = 'ApiError';+ this.errCode = errCode;+ this.httpStatus = httpStatus;+ this.httpStatusText = httpStatusText;+ }}export function isApiError(object: any): object is ApiError {