Skip to content

Commit

Permalink
Merge pull request #169 from amosproj/dev-#141
Browse files Browse the repository at this point in the history
Implementation of Dev #141
  • Loading branch information
Waldleufer authored Jul 13, 2021
2 parents e2484d1 + 49e07b3 commit 8e91b72
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
17 changes: 17 additions & 0 deletions frontend/src/assets/alert/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {*} error error message status code(400/502/401) recieved from SimaPro API
*/

export function ErrorAlert(error) {
if (error === 400) {
alert(
'There are no preset calculation settings for this product. Please contact your system administrator.'
);
} else if (error === 502) {
alert(
'You tried to request data for multiple projects at once. Handling this error is work in progress. For now, please restart both frontend and backend to resolve this error.'
);
} else if (error === 401) {
alert('Please verify the SimaPro cerdentials provided at the backend.');
}
}
20 changes: 18 additions & 2 deletions frontend/src/interface/BackendConnect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import { processBackendData } from 'interface/processBackendData';
import { dummyProcessBackendData } from 'interface/processBackendData';
import { ErrorAlert } from 'assets/alert/alert';
/**
* Get request to det the details of all the projects from the API via backend.
* @returns the list of all the projects.
Expand Down Expand Up @@ -34,7 +35,7 @@ export async function getSimaProProjects() {
*/
export async function postCalculationRequest(projectId, scenarioName, callback) {
// Bypass using the SimaPro Data
const useDummyData = true;
const useDummyData = false;

if (useDummyData) {
return dummyPostCalculationRequest(projectId, scenarioName, callback);
Expand All @@ -53,6 +54,19 @@ export async function postCalculationRequest(projectId, scenarioName, callback)

.then(function (data) {
processBackendData(data, scenarioName, callback);
})

// Read the errors from SimaPro and throw alerts.
.catch((error) => {
console.log(error);
let errorMessage = JSON.stringify(error);
if (errorMessage.split(/[ ,:,\\]/).includes('400')) {
ErrorAlert(400);
} else if (errorMessage.split(/[ ,:,\\]/).includes('502')) {
ErrorAlert(502);
} else if (errorMessage.split(/[ ,:,\\]/).includes('401')) {
ErrorAlert(401);
}
});
}

Expand All @@ -65,6 +79,8 @@ function dummyPostCalculationRequest(projectId, scenarioName, callback) {
* This request is caught by the backend.
* Which then checks if the calculation is stored based on the calculationId generated.
* If the calculation is stored returns the results of calculation here.
*
* This function is not used at present. Can be used in future.
*/
export async function postCalculationRequestCustomSetup(projectId, processId, processName) {
// POST request using axios with set headers
Expand Down Expand Up @@ -113,7 +129,7 @@ export async function postCalculationRequestCustomSetup(projectId, processId, pr

/**
* Getrequest to get the processes for a model based on the project Id
*
* This function is not used at present. Can be used in future.
*/
export async function getProjectProcesses(projectId) {
const headers = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/interface/simaProInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { simaProTypes } from 'resources/globalConstants/SimaProProductCategories
import { processScenarios } from './processProjects';

// Toggle to NOT use SimaPro Data
let useDummyData = true;
let useDummyData = false;

/**
*
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock

This file was deleted.

0 comments on commit 8e91b72

Please sign in to comment.