Convert the classification result into an HTTP response
| 146 | |
| 147 | // Convert the classification result into an HTTP response |
| 148 | auto to_response(classification_result res) -> http_response |
| 149 | { |
| 150 | if (res.type_ == obj_type::general_error) |
| 151 | // Send a 500 response back if we have a general error |
| 152 | return {.status_code_ = 500, .body_ = res.details_}; |
| 153 | else if (res.type_ == obj_type::cancelled) |
| 154 | { |
| 155 | // Send a 503 response back if the computation is cancelled |
| 156 | return {.status_code_ = 503, .body_ = "cancelled"}; |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | // Send a success response back, with the object type, accuracy and details |
| 161 | std::ostringstream oss; |
| 162 | oss << as_string(res.type_) << " (" << res.accuracy_ << ")\n" << res.details_; |
| 163 | return {.status_code_ = 200, .body_ = oss.str()}; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Handler for the "classify" request type |
| 168 | auto handle_classify_request(http_request const & req) -> ex::sender auto |
nothing calls this directly
no test coverage detected