Skip to content

Commit

Permalink
changed utils.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
johncalesp committed Mar 29, 2023
1 parent 5697d6e commit 2349588
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 10 additions & 4 deletions skyline-vscode/react-ui/src/utils/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CENTML_CLOUD_PROVIDERS_URL,
deploymentScatterGraphColorSize,
} from "../data/properties";
import {fetchingURLErrors} from '../utils/utils';
import {getErrMsgFromInvalidURL} from '../utils/utils';
import { cloudProviderSchema } from "../schema/CloudProvidersSchema";

const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors)
Expand Down Expand Up @@ -67,13 +67,19 @@ export const loadJsonFiles = async (habitatData, additionalProviders) => {
}
}
} else {
errors.push(fetchingURLErrors("schemaValidationErrors",resp,validate));
errors.push({
msg: `invalid data format from url: ${resp.url}`,
invalidFields: validate.errors.map((err) => ({
field: err.instancePath,
err: err.message,
})),
});
}
} catch (error) {
errors.push(fetchingURLErrors("noJsonResponseFromUrl",resp,null));
errors.push(getErrMsgFromInvalidURL("noJsonResponseFromUrl",resp));
}
} else {
errors.push(fetchingURLErrors(null,resp,null));
errors.push(getErrMsgFromInvalidURL("invalidUrl",resp));
}
}
return {
Expand Down
17 changes: 5 additions & 12 deletions skyline-vscode/react-ui/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,18 @@ export function currencyFormat(cost) {
return scientificFormater.format(cost);
}

export function fetchingURLErrors(type, response, validationErrors) {
export function getErrMsgFromInvalidURL(type, response) {
const code = `status: ${response?.statusText} | code: ${response?.status}`;
switch (type) {
case "schemaValidationErrors":
return {
msg: `invalid data format from url: ${response?.url}`,
invalidFields: validationErrors?.errors.map((err) => ({
field: err.instancePath,
err: err.message,
})),
};
case "noJsonResponseFromUrl":
return {
msg: `no json data from url: ${response?.url}`,
code: `status: ${response?.statusText} | code: ${response?.status}`,
code
};
default: // url is not accesible
return {
msg: `error reading from url: ${response?.url}`,
code: `status: ${response?.statusText} | code: ${response?.status}`,
msg: `url is not accesible: ${response?.url}`,
code
};
}
}

0 comments on commit 2349588

Please sign in to comment.