diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-07-18 10:58:53 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-07-18 10:58:53 +0200 |
| commit | 84ba09387e3305aaef1ccb63db5207ae5ad6b936 (patch) | |
| tree | e0a73ee6468c45e0c62827549d7a6be0f1217e25 /src | |
| parent | e7692dd1156bb3abbb19aa8a1f0f35417733c91f (diff) | |
Send the error back to the client
Diffstat (limited to 'src')
| -rw-r--r-- | src/api.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -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; } } |
