From 4d0f3e9eb98e723d17e59201360f4a73b6d39484 Mon Sep 17 00:00:00 2001 From: Kyle Morel Date: Thu, 3 Feb 2022 14:25:34 -0800 Subject: [PATCH 1/3] Include file hash in error response --- app/src/components/fileCache.js | 1 + app/src/routes/v2/template.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/components/fileCache.js b/app/src/components/fileCache.js index 5b962c2..0cd9b97 100644 --- a/app/src/components/fileCache.js +++ b/app/src/components/fileCache.js @@ -129,6 +129,7 @@ class FileCache { result.errorType = 405; result.errorMsg = `File already cached. Hash '${result.hash}'.`; + result.hash = result.hash; return result; } } diff --git a/app/src/routes/v2/template.js b/app/src/routes/v2/template.js index 3b0c743..7c61121 100644 --- a/app/src/routes/v2/template.js +++ b/app/src/routes/v2/template.js @@ -21,7 +21,7 @@ templateRouter.post('/', upload, async (req, res) => { // TODO: If `carbone.uploadCount` is greater than 1, check `req.files` array const result = await fileCache.move(req.file.path, req.file.originalname); if (!result.success) { - return new Problem(result.errorType, { detail: result.errorMsg }).send(res); + return new Problem(result.errorType, { detail: result.errorMsg, hash: result.hash }).send(res); } else { res.setHeader('X-Template-Hash', result.hash); return res.send(result.hash); From 0e21612add0629f8d2e7c896ba6b7ccee8b2e750 Mon Sep 17 00:00:00 2001 From: Kyle Morel Date: Thu, 3 Feb 2022 14:31:42 -0800 Subject: [PATCH 2/3] Remove pointless self assignment --- app/src/components/fileCache.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/components/fileCache.js b/app/src/components/fileCache.js index 0cd9b97..5b962c2 100644 --- a/app/src/components/fileCache.js +++ b/app/src/components/fileCache.js @@ -129,7 +129,6 @@ class FileCache { result.errorType = 405; result.errorMsg = `File already cached. Hash '${result.hash}'.`; - result.hash = result.hash; return result; } } From 45ce05806fb6a8be730429e786d7ea1f32f0d96f Mon Sep 17 00:00:00 2001 From: Kyle Morel Date: Tue, 8 Feb 2022 11:31:32 -0800 Subject: [PATCH 3/3] Update api-sec.yaml --- app/src/docs/v2.api-spec.yaml | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/docs/v2.api-spec.yaml b/app/src/docs/v2.api-spec.yaml index d0417bd..e0b0e79 100644 --- a/app/src/docs/v2.api-spec.yaml +++ b/app/src/docs/v2.api-spec.yaml @@ -159,7 +159,38 @@ paths: "400": $ref: "#/components/responses/BadRequest" "405": - $ref: "#/components/responses/MethodNotAllowed" + description: Template already cached + content: + application/json: + schema: + type: object + required: + - type + - title + - status + - detail + - hash + properties: + type: + type: string + description: "What type of problem, link to explanation of problem" + example: https://httpstatuses.com/405 + title: + type: string + description: "Title of problem, generally the Http Status Code" + example: Method Not Allowed + status: + type: string + description: The Http Status code + example: 405 + detail: + type: string + description: Short description of why this problem was raised. + example: File already cached. Hash '742d642a4704eb1babd8122ce0f03f209354279ae8292bb3961d13e21578b855'. + hash: + type: string + description: UUID for template cached on server. + example: 742d642a4704eb1babd8122ce0f03f209354279ae8292bb3961d13e21578b855 "422": $ref: "#/components/responses/UnprocessableEntity" default: