From a6ccd0fb08dd6828fe4d1e712a8fc96c99235da9 Mon Sep 17 00:00:00 2001 From: Chinmoy Chakraborty Date: Fri, 6 Oct 2023 22:18:52 +0530 Subject: [PATCH] Media Upload failure provides a reason. --- src/modules/form/form.controller.ts | 2 +- src/modules/form/form.service.spec.ts | 2 +- src/modules/form/form.service.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/form/form.controller.ts b/src/modules/form/form.controller.ts index 135ee46..b73217b 100644 --- a/src/modules/form/form.controller.ts +++ b/src/modules/form/form.controller.ts @@ -66,7 +66,7 @@ export class FormController { async single( @UploadedFiles() files: {form: Express.Multer.File[], mediaFiles: Express.Multer.File[]}, ) { - if (!files.form[0]) { + if (!files.form || !files.form[0]) { throw new BadRequestException('Form file is required!'); } const response = await this.formService.uploadForm(files.form[0], files.mediaFiles); diff --git a/src/modules/form/form.service.spec.ts b/src/modules/form/form.service.spec.ts index f8e1359..5f25458 100644 --- a/src/modules/form/form.service.spec.ts +++ b/src/modules/form/form.service.spec.ts @@ -127,7 +127,7 @@ describe('FormService', () => { expect(formService.uploadForm(mockXmlFile, mockMediaFiles)) .rejects - .toThrowError(new ServiceUnavailableException('Media upload failed!')); + .toThrowError(new ServiceUnavailableException('Media upload failed! Reason: Error')); }); it('form upload throws service unavailable exception when ODK server is unavailable', async () => { diff --git a/src/modules/form/form.service.ts b/src/modules/form/form.service.ts index 0571ee4..5f4d901 100644 --- a/src/modules/form/form.service.ts +++ b/src/modules/form/form.service.ts @@ -81,7 +81,7 @@ export class FormService { const mediaUploadResult = await this.uploadFormMediaFiles(mediaFiles); if (mediaUploadResult.error || !mediaUploadResult.data) { this.logger.error(`FormService::uploadForm: Media Files upload failed!`); - throw new ServiceUnavailableException('Media upload failed!'); + throw new ServiceUnavailableException(`Media upload failed! Reason: ${mediaUploadResult.error}`); } const xmlModificationError = this.replaceMediaFileName(formFile, mediaUploadResult.data); if (xmlModificationError != '') {