Return http status error on exit #15

Closed
opened 2022-01-31 15:44:07 +01:00 by Cpm · 1 comment
Contributor

Actually, the index.php file is containing some tests in case of qrcode creation POST request:

  if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096)
    $params['txt'] = $_POST['txt'];
  else
    exit("Wrong value for txt");

But, on error, the http status code returned is 200 OK.

It would be better if it returned the http status code 400 Bad Request in case of error.

Example of code:

  if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096)
    $params['txt'] = $_POST['txt'];
  else
  {
      http_response_code(400);
      exit("Wrong value for txt");     
  }

This need is very important to do log analysis.

Actually, the `index.php` file is containing some tests in case of qrcode creation POST request: ``` if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) $params['txt'] = $_POST['txt']; else exit("Wrong value for txt"); ``` But, on error, the http status code returned is `200 OK`. It would be better if it returned the http status code `400 Bad Request` in case of error. Example of code: ``` if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) $params['txt'] = $_POST['txt']; else { http_response_code(400); exit("Wrong value for txt"); } ``` This need is very important to do log analysis.
miraty added this to the 2.0.0 milestone 2022-01-31 15:54:59 +01:00
Owner

Done in 3fdd6f5eab.

Done in 3fdd6f5eab.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: miraty/libreqr#15
No description provided.