Skip to content

Return HTTP error codes in case of problems

Dinyar Rabady requested to merge fix/return_http_status_code into main

Previously we were always returning the HTTP status code 200 (although the status code we set in our payload was set correctly). This MR makes us return the correct status code on failure.

Belongs to #20 (closed).

Tested in the B40 lab:

Example of a good request with "200 OK" reply:

 ; curl -v localhost:8080/kcu1500_ugmt/algo_version/read
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /kcu1500_ugmt/algo_version/read HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 51
< Date: Mon, 13 Jun 2022 09:36:14 GMT
< 
{"message":"success","status":"200","value":65538}
* Connection #0 to host localhost left intact

Examples of bad requests and the associated "400 BAD REQUEST" error codes:

 ; curl -v localhost:8080/kcu1500_ugmt/lgo_version/read
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /kcu1500_ugmt/lgo_version/read HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 400 BAD REQUEST
< Content-Type: application/json
< Content-Length: 76
< Date: Mon, 13 Jun 2022 09:36:00 GMT
< 
{"message":"bad request: register not available","status":"400","value":-1}
* Connection #0 to host localhost left intact
 ; curl -v localhost:8080/kcu1500_ugt/algo_version/read
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /kcu1500_ugt/algo_version/read HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 400 BAD REQUEST
< Content-Type: application/json
< Content-Length: 73
< Date: Mon, 13 Jun 2022 09:36:18 GMT
< 
{"message":"bad request: board not available","status":"400","value":-1}
* Connection #0 to host localhost left intact
Edited by Dinyar Rabady

Merge request reports