From bee2333f7736f5b72a2fb971cca2a5707d32771b Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Thu, 25 Feb 2021 13:51:54 +0100 Subject: [PATCH] MediaService: Add MediaBackendError This get's thrown when the backend can't perform the required action. Signed-off-by: Philip Molares --- src/errors/errors.ts | 4 ++++ src/media/media-backend.interface.ts | 3 +++ src/media/media.service.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/errors/errors.ts b/src/errors/errors.ts index fca24a873..aaef8afc3 100644 --- a/src/errors/errors.ts +++ b/src/errors/errors.ts @@ -31,3 +31,7 @@ export class TooManyTokensError extends Error { export class PermissionsUpdateInconsistentError extends Error { name = 'PermissionsUpdateInconsistentError'; } + +export class MediaBackendError extends Error { + name = 'MediaBackendError'; +} diff --git a/src/media/media-backend.interface.ts b/src/media/media-backend.interface.ts index 8de2c42fd..634571392 100644 --- a/src/media/media-backend.interface.ts +++ b/src/media/media-backend.interface.ts @@ -11,6 +11,7 @@ export interface MediaBackend { * Saves a file according to backend internals. * @param buffer File data * @param fileName Name of the file to save. Can include a file extension. + * @throws {MediaBackendError} - there was an error saving the file * @return Tuple of file URL and internal backend data, which should be saved. */ saveFile(buffer: Buffer, fileName: string): Promise<[string, BackendData]>; @@ -19,6 +20,7 @@ export interface MediaBackend { * Retrieve the URL of a previously saved file. * @param fileName String to identify the file * @param backendData Internal backend data + * @throws {MediaBackendError} - there was an error deleting the file */ getFileURL(fileName: string, backendData: BackendData): Promise; @@ -26,6 +28,7 @@ export interface MediaBackend { * Delete a file from the backend * @param fileName String to identify the file * @param backendData Internal backend data + * @throws {MediaBackendError} - there was an error retrieving the url */ deleteFile(fileName: string, backendData: BackendData): Promise; } diff --git a/src/media/media.service.ts b/src/media/media.service.ts index 2272c0a06..3869c6da6 100644 --- a/src/media/media.service.ts +++ b/src/media/media.service.ts @@ -67,6 +67,8 @@ export class MediaService { * @param {string} noteId - the id or alias of the note which will be associated with the new file. * @return {string} the url of the saved file * @throws {ClientError} the MIME type of the file is not supported. + * @throws {NotInDBError} - the note or user is not in the database + * @throws {MediaBackendError} - there was an error saving the file */ async saveFile( fileBuffer: Buffer, @@ -110,6 +112,7 @@ export class MediaService { * @return {string} the url of the saved file * @throws {PermissionError} the user is not permitted to delete this file. * @throws {NotInDBError} - the file entry specified is not in the database + * @throws {MediaBackendError} - there was an error deleting the file */ async deleteFile(filename: string, username: string): Promise { this.logger.debug( @@ -136,6 +139,7 @@ export class MediaService { * @param {string} filename - the name of the file entry to find * @return {MediaUpload} the file entry, that was searched for * @throws {NotInDBError} - the file entry specified is not in the database + * @throws {MediaBackendError} - there was an error retrieving the url */ async findUploadByFilename(filename: string): Promise { const mediaUpload = await this.mediaUploadRepository.findOne(filename, {