Fix: add not found response
All checks were successful
Build and push image / release-image (push) Successful in 1m39s
All checks were successful
Build and push image / release-image (push) Successful in 1m39s
This commit is contained in:
@@ -6,6 +6,8 @@ import {
|
||||
S3ClientConfig,
|
||||
GetObjectCommand,
|
||||
GetObjectCommandInput,
|
||||
GetObjectCommandOutput,
|
||||
NoSuchKey,
|
||||
} from '@aws-sdk/client-s3';
|
||||
|
||||
@Injectable()
|
||||
@@ -28,14 +30,22 @@ export class AppService {
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
async getObject(getObjectConfig: GetObjectCommandInput): Promise<Readable> {
|
||||
async getObject(getObjectConfig: GetObjectCommandInput): Promise<Readable | null> {
|
||||
const command = new GetObjectCommand(getObjectConfig);
|
||||
const res = await this.s3Client.send(command);
|
||||
let res: GetObjectCommandOutput;
|
||||
try {
|
||||
res = await this.s3Client.send(command);
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof NoSuchKey)
|
||||
return null;
|
||||
throw err;
|
||||
}
|
||||
if (!res.Body)
|
||||
throw new HttpException(
|
||||
's3 get object failed',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
|
||||
return res.Body as Readable;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user