From 23ef9b8cd6d4ff34daa35b5591a5bdb9d688066b Mon Sep 17 00:00:00 2001 From: Taso Date: Mon, 8 Mar 2021 12:28:39 -0500 Subject: [PATCH] chore(server/photo): Added try/catch to missing sql query --- resources/server/sv_photo.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/server/sv_photo.ts b/resources/server/sv_photo.ts index 3ee99e0..3f694f4 100644 --- a/resources/server/sv_photo.ts +++ b/resources/server/sv_photo.ts @@ -14,8 +14,7 @@ async function uploadPhoto(identifier: string, image: string) { async function getPhotosByIdentifier(identifier: string): Promise { const query = 'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC'; const [results] = await pool.query(query, [identifier]); - const photos = results; - return photos; + return results; } async function deletePhoto(photo: IPhoto, identifier: string) { @@ -38,9 +37,15 @@ onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => { onNet(events.CAMERA_FETCH_PHOTOS, async () => { const _source = getSource(); - const identifier = getIdentifier(_source); - const photos = await getPhotosByIdentifier(identifier); - emitNet(events.CAMERA_SEND_PHOTOS, source, photos); + try { + const identifier = getIdentifier(_source); + const photos = await getPhotosByIdentifier(identifier); + emitNet(events.CAMERA_SEND_PHOTOS, _source, photos); + } catch (e) { + photoLogger.error(`Failed to fetch photos, ${e.message}`, { + source: _source, + }); + } }); onNet(events.CAMERA_DELETE_PHOTO, async (photo: IPhoto) => {