diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 2458533eb820e2252f1a3e17f8c108d80b47e366..866de09836877af4e9aa04b7a50fcca5d2d48744 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -251,7 +251,23 @@ const handleIdentityLogin = (identity, uuid, token) => { async function executeRestfulFunction(type, that, fn, config, ...args) { const { currentlyAuthenticatedIdentity, viamApi, currentlyLoadedIdentity } = window; - const response = await fn.apply(that, [config, ...args]); + let response; + try { + response = await fn.apply(that, [config, ...args]); + } catch (error) { + if (error.response) { + //Resposnse with status code != 2xx still has valid response + response = error.response; + } else { + //Connection error or similar + const data = { + "data": "", + "code": "999", + "status": error.message + }; + return data; + } + } const identity = currentlyAuthenticatedIdentity || currentlyLoadedIdentity; const { code, status } = response.data; @@ -275,8 +291,12 @@ async function executeRestfulFunction(type, that, fn, config, ...args) { const uuid = loginResponse.data.data["Uuid"]; const token = loginResponse.data.data["Session"]; handleIdentityLogin(identity, uuid, token); - const { data } = await fn.apply(that, [config, ...args]); - return data; + try { + response = await fn.apply(that, [config, ...args]); + } catch (error) { + response = error.response; + } + return response.data; } window.executeRestfulFunction = executeRestfulFunction;