From 84ba09387e3305aaef1ccb63db5207ae5ad6b936 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Fri, 18 Jul 2025 10:58:53 +0200 Subject: Send the error back to the client --- src/api.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/api.c b/src/api.c index 0456759..16cde8c 100644 --- a/src/api.c +++ b/src/api.c @@ -189,13 +189,15 @@ static enum MHD_Result handler( if(conn->state == OP_PENDING) { if(!conn->target_set) { - goto err; + response = MHD_create_response_from_buffer_static(0, NULL); + ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); + goto end; } if(api->dht->lookup.state != OP_EMPTY) { - // @COMPL We should return some nice error message to the user - // here about how they lost a race - goto err; + response = MHD_create_response_from_buffer_static(0, NULL); + ret = MHD_queue_response(connection, MHD_HTTP_CONFLICT, response); + goto end; } // Start a lookup @@ -204,26 +206,27 @@ static enum MHD_Result handler( prom_gauge_set(lookup_state, api->dht->lookup.state, NULL); } else if(conn->state == OP_EMPTY) { if(conn->target_set) { - goto err; + response = MHD_create_response_from_buffer_static(0, NULL); + ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); + goto end; } if(api->dht->lookup.state != OP_COMPLETED) { - // @COMPL We should return some nice error message to the user - // here about how they lost a race - goto err; + response = MHD_create_response_from_buffer_static(0, NULL); + ret = MHD_queue_response(connection, MHD_HTTP_CONFLICT, response); + goto end; } api->dht->lookup.state = OP_EMPTY; prom_gauge_set(lookup_state, api->dht->lookup.state, NULL); } else { - goto err; + response = MHD_create_response_from_buffer_static(0, NULL); + ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); + goto end; } ret = queue_lookup_response(api, connection, &response, true); goto end; -err: - pthread_mutex_unlock(&api->dht->mutex); - return MHD_NO; } } -- cgit v1.2.3