From 2fc88fffcce1e2745cc03a380ec4ecf3d867173d Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:51:58 +0000 Subject: [PATCH 1/3] lint: run on README --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9c1e0404..1ee96525 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ -Summary -======= - -Product | Validator Web Frontend ---- | --- -Description | Vue.js app website for the IATI Validator. -Website | [https://validator.iatistandard.org/](https://validator.iatistandard.org) -Related | [js-validator-api](https://github.com/IATI/js-validator-api), [validator-services](https://github.com/IATI/validator-services) -Documentation | [https://developer.iatistandard.org/](https://developer.iatistandard.org/) -Technical Issues | https://github.com/IATI/validator-web/issues -Support | https://iatistandard.org/en/guidance/get-support/ +# Summary + +| Product | Validator Web Frontend | +| ---------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| Description | Vue.js app website for the IATI Validator. | +| Website | [https://validator.iatistandard.org/](https://validator.iatistandard.org) | +| Related | [js-validator-api](https://github.com/IATI/js-validator-api), [validator-services](https://github.com/IATI/validator-services) | +| Documentation | [https://developer.iatistandard.org/](https://developer.iatistandard.org/) | +| Technical Issues | https://github.com/IATI/validator-web/issues | +| Support | https://iatistandard.org/en/guidance/get-support/ | # Vue Template From 36e87947435860b578236ebce8789d53d04ab61c Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:54:42 +0000 Subject: [PATCH 2/3] feat: show detailed messages from validator-services --- src/components/LocalFilesValidator.vue | 17 +++++++++++++++-- src/components/RemoteFIlesValidator.vue | 23 ++++++++++++----------- src/utils/api/validate.js | 11 +++++++++-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/components/LocalFilesValidator.vue b/src/components/LocalFilesValidator.vue index d9aa1a70..b374585f 100644 --- a/src/components/LocalFilesValidator.vue +++ b/src/components/LocalFilesValidator.vue @@ -13,6 +13,7 @@ const activeStep = ref(1); const files = ref([]); const requestStatus = ref(""); // 'pending' | 'draft' | 'success' | 'error' = 'draft' + const uploadErrorMessage = ref(""); const onAddFiles = (_files) => { files.value = _files; @@ -24,7 +25,14 @@ const uploadFiles = () => { const handleError = (error) => { - console.error(error); + if (typeof error === "object" && typeof error.message === "string") { + try { + const errorResponse = JSON.parse(error.message); + uploadErrorMessage.value = errorResponse.message; + } catch (err) { + console.error(err); + } + } requestStatus.value = "error"; }; @@ -62,7 +70,12 @@

Upload your IATI files and start validation.

- File(s) uploading failed. Check your files and try again. + + File(s) have been uploaded successfully diff --git a/src/components/RemoteFIlesValidator.vue b/src/components/RemoteFIlesValidator.vue index 966c037e..4a8bdce9 100644 --- a/src/components/RemoteFIlesValidator.vue +++ b/src/components/RemoteFIlesValidator.vue @@ -11,6 +11,7 @@ const props = defineProps({ workspaceID: { type: String, default: "" } }); const activeStep = ref(1); const requestStatus = ref(""); // 'pending' | 'draft' | 'success' | 'error' = 'draft' + const includeGenericErrorMessage = ref(true); const requestErrorMessage = ref(""); const urls = ref(""); const incorrectURLs = ref([]); @@ -51,22 +52,19 @@ requestStatus.value = "error"; if (error && error.message) { requestErrorMessage.value = error.message; + if (error.cause.status === 503) { + includeGenericErrorMessage.value = false; + } } else { - console.log("Error: ", error); + console.log(`Error received from IATI Validator Services: ${error}`); } }; requestStatus.value = "pending"; parallelUpload(correctURLs).subscribe({ - next: (response) => { - const responseText = Array.isArray(response) && response.length ? response[0] : response; - if (responseText === "success") { - activeStep.value = 3; - requestStatus.value = "success"; - } else { - requestStatus.value = "error"; - requestErrorMessage.value = responseText; - } + next: () => { + activeStep.value = 3; + requestStatus.value = "success"; }, error: handleError, }); @@ -98,7 +96,10 @@

Fetch the files from the web.

- File(s) uploading failed. Check your files and try again.
{{ requestErrorMessage }} + + {{ requestErrorMessage }}
File(s) have been uploaded successfully diff --git a/src/utils/api/validate.js b/src/utils/api/validate.js index fc7f900d..e1d2b31a 100644 --- a/src/utils/api/validate.js +++ b/src/utils/api/validate.js @@ -33,11 +33,18 @@ export const fetchFileFromURL = async (fileUrl, workspaceID) => { }); if (req.status === 200) return "success"; + + let errorMessage = ""; if (req.status === 422) { const error = await req.json(); - - return error.message.includes(fileUrl) ? error.message : `${error.url} - ${error.message}`; + errorMessage = error.message.includes(fileUrl) ? error.message : `${error.url} - ${error.message}`; + } else if (req.status === 503) { + const error = await req.json(); + errorMessage = error.message; + } else { + errorMessage = req.text; } + throw new Error(errorMessage, { cause: { status: req.status } }); }; export const getTempWorkspaceURL = (workspaceID) => `${SERVICES_URL}/pvt/adhoc/session/?sessionId=${workspaceID}`; From 8ff18f7d7a62452598a8d8ca67cff21f77b6544f Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:55:59 +0000 Subject: [PATCH 3/3] test: tests for when vs in maintenance mode --- cypress/integration/checkData.spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cypress/integration/checkData.spec.js b/cypress/integration/checkData.spec.js index 63a33751..0386696e 100644 --- a/cypress/integration/checkData.spec.js +++ b/cypress/integration/checkData.spec.js @@ -73,4 +73,28 @@ describe("The Ad Hoc Validate Check Data page", () => { cy.contains("a", "View Progress and Reports").click(); cy.contains("Failed to load iati data please try again later"); }); + it("displays error message uploading a file when validator-services is in maintenance mode", () => { + cy.intercept("POST", "https://*api.iatistandard.org/vs/pvt/adhoc/upload?*", { + statusCode: 503, + body: { message: "Validator services is in read-only mode for maintenance" }, + }); + cy.get("input[type=file").selectFile("cypress/fixtures/iati-act-no-errors.xml", { force: true }); + cy.contains("iati-act-no-errors.xml"); + cy.contains("button", "Upload").should("not.be.disabled").click(); + cy.contains("Validator services is in read-only mode for maintenance", { timeout: 20000 }); + cy.contains("a", "View Progress and Reports").parent().should("have.class", "pointer-events-none"); + }); + it("displays error message fetching a url when validator-services is in maintenance mode", () => { + cy.intercept("POST", "https://*api.iatistandard.org/vs/pvt/adhoc/url?**/**", { + statusCode: 503, + body: { message: "Validator services is in read-only mode for maintenance" }, + }); + cy.contains("URL to a remote file").click(); + cy.get("#url").type( + "https://raw.githubusercontent.com/IATI/IATI-Extra-Documentation/version-2.03/en/activity-standard/activity-standard.xml", + ); + cy.contains("button", "Fetch").should("not.be.disabled").click(); + cy.contains("Validator services is in read-only mode for maintenance", { timeout: 20000 }); + cy.contains("a", "View Progress and Reports").parent().should("have.class", "pointer-events-none"); + }); });