Skip to content

Commit

Permalink
fix send img crash (#230)
Browse files Browse the repository at this point in the history
* fix send img crash

* Fix code formatting

---------

Co-authored-by: Format Bot <[email protected]>
  • Loading branch information
dragazo and Format Bot authored Apr 27, 2024
1 parent 73d97c7 commit 00044ff
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/procedures/utils/api-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ApiConsumer extends NBService {
let requestImage = () => {
logger.trace("requesting image from", fullUrl);
const deferred = defer();
const imgResponse = request.get(fullUrl);
const imgResponse = request.get(fullUrl, (err) => deferred.reject(err));
delete imgResponse.headers["cache-control"];
imgResponse.on("response", (res) => {
try {
Expand Down Expand Up @@ -240,11 +240,16 @@ class ApiConsumer extends NBService {
}

// sends an image to the user
_sendImage(queryOptions) {
return this._requestImage(queryOptions)
.then((imageBuffer) => {
this._sendImageBuffer(imageBuffer);
});
async _sendImage(queryOptions) {
let img;
try {
img = await this._requestImage(queryOptions);
} catch (e) {
this._logger.trace("failed to load image", e);
return "failed to load image";
}

return this._sendImageBuffer(img);
}

// helper test the response
Expand Down

0 comments on commit 00044ff

Please sign in to comment.