From cc5255d977bf8c5f0a4e8d9709c8fc13879770a4 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 30 Jul 2019 16:31:19 -0300 Subject: [PATCH 1/4] Ignore 404 error when fetching app info from Marketplace --- app/apps/client/admin/appManage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/apps/client/admin/appManage.js b/app/apps/client/admin/appManage.js index c6d2d73dbdbd..460bea32932e 100644 --- a/app/apps/client/admin/appManage.js +++ b/app/apps/client/admin/appManage.js @@ -95,6 +95,10 @@ const attachMarketplaceInformation = async (appId, version, _app) => { attachBundlesApps(bundledIn, _app); } catch (error) { + if (error.xhr && error.xhr.status === 404) { + return; + } + handleAPIError(error); } }; From b1d43ee986dae69e25a4691abff40d4fe76bfae1 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 30 Jul 2019 17:44:40 -0300 Subject: [PATCH 2/4] Forward HTTP 400 errors from Marketplace --- app/apps/client/admin/appManage.js | 6 ++---- app/apps/server/communication/rest.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/apps/client/admin/appManage.js b/app/apps/client/admin/appManage.js index 460bea32932e..149f53cc38a9 100644 --- a/app/apps/client/admin/appManage.js +++ b/app/apps/client/admin/appManage.js @@ -95,11 +95,9 @@ const attachMarketplaceInformation = async (appId, version, _app) => { attachBundlesApps(bundledIn, _app); } catch (error) { - if (error.xhr && error.xhr.status === 404) { - return; + if (error.xhr && error.xhr.status >= 500 && error.xhr.status <= 599) { + handleAPIError(error); } - - handleAPIError(error); } }; diff --git a/app/apps/server/communication/rest.js b/app/apps/server/communication/rest.js index 924a546575a2..d689620e1482 100644 --- a/app/apps/server/communication/rest.js +++ b/app/apps/server/communication/rest.js @@ -310,7 +310,12 @@ export class AppsRestApi { }); } catch (e) { orchestrator.getRocketChatLogger().error('Error getting the App information from the Marketplace:', e.response.data); - return API.v1.internalError(); + + if (e.response.statusCode >= 500 && e.response.statusCode <= 599) { + return API.v1.internalError(); + } + + return API.v1.failure(); } if (!result || result.statusCode !== 200 || result.data.length === 0) { @@ -337,7 +342,12 @@ export class AppsRestApi { }); } catch (e) { orchestrator.getRocketChatLogger().error('Error getting the App update info from the Marketplace:', e.response.data); - return API.v1.internalError(); + + if (e.response.statusCode >= 500 && e.response.statusCode <= 599) { + return API.v1.internalError(); + } + + return API.v1.failure(); } if (result.statusCode !== 200 || result.data.length === 0) { From ad6851d4b925c78dc639b7fffb05d370224f8caf Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 30 Jul 2019 19:34:32 -0300 Subject: [PATCH 3/4] Better HTTP 404 handling --- app/apps/client/admin/appManage.js | 6 ++++-- app/apps/server/communication/rest.js | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/apps/client/admin/appManage.js b/app/apps/client/admin/appManage.js index 149f53cc38a9..460bea32932e 100644 --- a/app/apps/client/admin/appManage.js +++ b/app/apps/client/admin/appManage.js @@ -95,9 +95,11 @@ const attachMarketplaceInformation = async (appId, version, _app) => { attachBundlesApps(bundledIn, _app); } catch (error) { - if (error.xhr && error.xhr.status >= 500 && error.xhr.status <= 599) { - handleAPIError(error); + if (error.xhr && error.xhr.status === 404) { + return; } + + handleAPIError(error); } }; diff --git a/app/apps/server/communication/rest.js b/app/apps/server/communication/rest.js index d689620e1482..59f511d02c75 100644 --- a/app/apps/server/communication/rest.js +++ b/app/apps/server/communication/rest.js @@ -315,6 +315,10 @@ export class AppsRestApi { return API.v1.internalError(); } + if (e.response.statusCode === 404) { + return API.v1.notFound(); + } + return API.v1.failure(); } @@ -347,6 +351,10 @@ export class AppsRestApi { return API.v1.internalError(); } + if (e.response.statusCode === 404) { + return API.v1.notFound(); + } + return API.v1.failure(); } From c9e4f157d44854099e147474e842b16d54df4e1e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Thu, 1 Aug 2019 14:50:33 -0300 Subject: [PATCH 4/4] Update rest.js --- app/apps/server/communication/rest.js | 38 +++++++++++---------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/apps/server/communication/rest.js b/app/apps/server/communication/rest.js index 59f511d02c75..63e8502f972e 100644 --- a/app/apps/server/communication/rest.js +++ b/app/apps/server/communication/rest.js @@ -292,6 +292,20 @@ export class AppsRestApi { }, }); + const handleError = (message, e) => { + orchestrator.getRocketChatLogger().error(message, e.response.data); + + if (e.response.statusCode >= 500 && e.response.statusCode <= 599) { + return API.v1.internalError(); + } + + if (e.response.statusCode === 404) { + return API.v1.notFound(); + } + + return API.v1.failure(); + }; + this.api.addRoute(':id', { authRequired: true, permissionsRequired: ['manage-apps'] }, { get() { if (this.queryParams.marketplace && this.queryParams.version) { @@ -309,17 +323,7 @@ export class AppsRestApi { headers, }); } catch (e) { - orchestrator.getRocketChatLogger().error('Error getting the App information from the Marketplace:', e.response.data); - - if (e.response.statusCode >= 500 && e.response.statusCode <= 599) { - return API.v1.internalError(); - } - - if (e.response.statusCode === 404) { - return API.v1.notFound(); - } - - return API.v1.failure(); + return handleError('Error getting the App information from the Marketplace:', e); } if (!result || result.statusCode !== 200 || result.data.length === 0) { @@ -345,17 +349,7 @@ export class AppsRestApi { headers, }); } catch (e) { - orchestrator.getRocketChatLogger().error('Error getting the App update info from the Marketplace:', e.response.data); - - if (e.response.statusCode >= 500 && e.response.statusCode <= 599) { - return API.v1.internalError(); - } - - if (e.response.statusCode === 404) { - return API.v1.notFound(); - } - - return API.v1.failure(); + return handleError('Error getting the App update info from the Marketplace:', e); } if (result.statusCode !== 200 || result.data.length === 0) {