From 9dca27177fa7554f0f7cbee28fa7ea8b7eef9d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 17 Nov 2018 23:59:57 +0100 Subject: [PATCH] fixed js logic for errors --- web/js/logic.js | 4 ++-- web/send.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/js/logic.js b/web/js/logic.js index 5d3346d..45ebdb7 100644 --- a/web/js/logic.js +++ b/web/js/logic.js @@ -34,10 +34,10 @@ function send() if (xhr.readyState !== 4) return; console.log('Status: ' + xhr.status); - if (xhr.status === 200) + if (xhr.status === 200 || xhr.status === 401 || xhr.status === 403 || xhr.status === 412) { let resp = JSON.parse(xhr.responseText); - if (!resp.success) + if (!resp.success || xhr.status !== 200) { if (resp.errhighlight === 101) uid.classList.add('input-invalid'); if (resp.errhighlight === 102) key.classList.add('input-invalid'); diff --git a/web/send.php b/web/send.php index a8d101d..1703546 100644 --- a/web/send.php +++ b/web/send.php @@ -42,7 +42,7 @@ try $stmt->execute(['uid' => $user_id]); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (count($datas)<=0) die(json_encode(['success' => false, 'error' => ERR::USER_NOT_FOUND, 'errhighlight' => 101, 'message' => 'User not found'])); + if (count($datas)<=0) api_return(401, ['success' => false, 'error' => ERR::USER_NOT_FOUND, 'errhighlight' => 101, 'message' => 'User not found']); $data = $datas[0]; if ($data === null) api_return(401, ['success' => false, 'error' => ERR::USER_NOT_FOUND, 'errhighlight' => 101, 'message' => 'User not found']);