minio-js
minio-js copied to clipboard
presignedUrl generate XML file with error instead of generating error in callback
Hello everyone,
I'm working on a NestJS API using Express structure. I'm trying to generate a link from an object in a bucket with the function presignedGetObject.
I intentionally put a wrong objectName to see if i handled the error like I wanted but it occurs that the function send back an url containing a XML file with the error I should get in my callback : NoSuchKey
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>query.filePath</Key>
<BucketName>luc</BucketName>
<Resource>/luc/query.filePath</Resource>
<RequestId>16F3E13DB9BBF1D0</RequestId>
<HostId>e08141ca-1f55-4dda-b71c-abd9251ef3c3</HostId>
</Error>
Here is the code I use to get this error : The service containing the functions for my controllers (route handlers)
generateDownloadLink(bucketName: string, filePath: string): Promise<string> {
if (process.env.NODE_ENV === 'development') this.logger.debug('Method generateDownloadLink called');
return new Promise((resolve, reject) => {
this.minioClient.presignedGetObject(
bucketName,
filePath,
60,
{ 'response-content-disposition': 'attachment;' },
(error, result) => {
if (error) reject(error);
resolve(result);
},
);
});
}
The route handler (controller) :
@Get()
async download(@Req() request: Request, @Res() response: Response) {
const query = request.query as { filePath: string };
const responseMessage: ResponseMessage = {
statusCode: HttpStatus.CREATED,
timestamp: new Date().toISOString(),
path: request.url,
};
try {
const link = await this.minioClientService.generateDownloadLink(
request.user.bucketName,
'query.filePath',
);
responseMessage.message = link;
} catch (error) {
responseMessage.message = 'Une erreur est survenue lors de la récupération des données';
responseMessage.statusCode = HttpStatus.NOT_FOUND;
responseMessage.error = error.message;
}
response.json(responseMessage);
}
My server app is running on localhost:3000
Using postman to make a GET request i obtain : https://gyazo.com/13eaa6dcee43e27bbaacd0564770701d
When I click on the link in the message field, it gives me the content I put at the beginning of this message
I saw only 1 issue related to my case : https://github.com/aws/aws-sdk-js/issues/1893
I don't know if i misunderstood something in the function or if I use it wrong but I thought that if an error occurred, the error param wold have a value.
still waiting ...
this would be a responsibility of client application. as the sdk could only generate the url. and the url is requested by the http client which needs to handle this.