Skip to content

Commit 01e9a37

Browse files
committed
Add NotFoundException handling for missing filestorage entries
1 parent 7b0cf67 commit 01e9a37

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/core/filestorage/filestorage.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BadRequestException, HttpException, HttpStatus, Injectable } from '@nestjs/common';
1+
import { BadRequestException, HttpException, HttpStatus, Injectable, NotFoundException } from '@nestjs/common';
22
import { ModuleRef } from '@nestjs/core';
33
import { InjectModel } from '@nestjs/mongoose';
44
import { FactorydriveService } from '@the-software-compagny/nestjs_module_factorydrive';
@@ -140,6 +140,11 @@ export class FilestorageService extends AbstractServiceSchema {
140140
): Promise<[Document<any, any, Filestorage> & Filestorage, NodeJS.ReadableStream | null, (Document<any, any, Filestorage> & Filestorage) | null]> {
141141
const data = await super.findOne<Document<any, any, Filestorage> & Filestorage>(filter, projection, options)
142142
if (data.type === FsType.FILE) {
143+
const storageRequest = await this.storage.getDisk(data.namespace).exists(data.path)
144+
if (!storageRequest.exists) {
145+
this.logger.warn(`Filestorage ${data._id} not found in storage`)
146+
throw new NotFoundException(`Filestorage ${data._id} not found in storage`)
147+
}
143148
const stream = await this.storage.getDisk(data.namespace).getStream(data.path)
144149
return [data, stream, null]
145150
}

0 commit comments

Comments
 (0)