Skip to content

Commit

Permalink
fix: Fixed error on getQrCode and sessionState (close #959)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Oct 23, 2022
1 parent b0bf1f5 commit 5ed97e4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/controller/sessionController.js
Expand Up @@ -272,7 +272,7 @@ export async function getSessionState(req, res) {
try {
const { waitQrCode = false } = req.body;
const client = req.client;
const qr = await QRCode.toDataURL(client.urlcode);
const qr = client.urlcode ? await QRCode.toDataURL(client.urlcode) : null;

if ((client == null || client.status == null) && !waitQrCode)
return res.status(200).json({ status: 'CLOSED', qrcode: null });
Expand All @@ -291,14 +291,18 @@ export async function getSessionState(req, res) {

export async function getQrCode(req, res) {
try {
const qr = await QRCode.toDataURL(req.client.urlcode);
const img = Buffer.from(qr.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''), 'base64');
if (req.client.urlcode) {
const qr = req.client.urlcode ? await QRCode.toDataURL(req.client.urlcode) : null;

This comment has been minimized.

Copy link
@Saifallak

Saifallak Oct 23, 2022

Contributor

This check is not needed, since its already checked in if statements

const img = Buffer.from(qr.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''), 'base64');

res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length,
});
res.end(img);
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length,
});
res.end(img);
} else {
return res.status(200).json({ status: req.client.status, message: 'QRCode is not available...' });

This comment has been minimized.

Copy link
@Saifallak

Saifallak Oct 23, 2022

Contributor

This shouldn't be status 200, it's an error

}
} catch (ex) {
req.logger.error(ex);
return res.status(500).json({ status: 'error', message: 'Error retrieving QRCode' });
Expand Down

0 comments on commit 5ed97e4

Please sign in to comment.