From cc9d05e4cedd162bbb2a9d22dfe796dc066f6b37 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 18 Jun 2021 15:25:32 +0200 Subject: [PATCH] [FIX] web: http_service: 502 errors should be handled as connection lost Run Odoo behind nginx, load odoo, kill the server, and trigger the http service to make a request Before this commit it, the error code 502 was not handled After this commit, it is handled as if the server was unreachable altogether --- addons/web/static/src/core/network/http_service.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/web/static/src/core/network/http_service.js b/addons/web/static/src/core/network/http_service.js index 8c5e50789a1..13f25142ebe 100644 --- a/addons/web/static/src/core/network/http_service.js +++ b/addons/web/static/src/core/network/http_service.js @@ -2,11 +2,18 @@ import { registry } from "../registry"; +function checkResponseStatus(response) { + if (response.status === 502) { + throw new Error("Failed to fetch"); + } +} + export const httpService = { start() { return { async get(route, readMethod = "json") { const response = await fetch(route, { method: "GET" }); + checkResponseStatus(response); return response[readMethod](); }, async post(route, params = {}, readMethod = "json") { @@ -26,6 +33,7 @@ export const httpService = { method: "POST", }; const response = await fetch(route, info); + checkResponseStatus(response); return response[readMethod](); }, };