mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -05:00
MediaController: Handle errors when trying to save file
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
8e662167dc
commit
4cd80a3212
1 changed files with 13 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
BadRequestException,
|
||||||
Controller,
|
Controller,
|
||||||
Headers,
|
Headers,
|
||||||
Post,
|
Post,
|
||||||
|
@ -6,6 +7,7 @@ import {
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
|
import { ClientError, NotInDBError } from '../../../errors/errors';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { MediaService } from '../../../media/media.service';
|
import { MediaService } from '../../../media/media.service';
|
||||||
import { MulterFile } from '../../../media/multer-file.interface';
|
import { MulterFile } from '../../../media/multer-file.interface';
|
||||||
|
@ -33,10 +35,16 @@ export class MediaController {
|
||||||
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
|
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
|
||||||
'uploadImage',
|
'uploadImage',
|
||||||
);
|
);
|
||||||
const note = await this.notesService.getNoteByIdOrAlias(noteId);
|
try {
|
||||||
const url = await this.mediaService.saveFile(file, username, note.id);
|
const url = await this.mediaService.saveFile(file, username, noteId);
|
||||||
return {
|
return {
|
||||||
link: url,
|
link: url,
|
||||||
};
|
};
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ClientError || e instanceof NotInDBError) {
|
||||||
|
throw new BadRequestException(e.message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue