{"record":{"id":"4a9559b5ab46a508","repo":"tursodatabase/turso","slug":"http-error-status-int-response-statuscode","errorCode":null,"errorMessage":"HTTP error! status: {(int)response.StatusCode}","messagePattern":"HTTP error! status: (.+?)","errorType":"exception","errorClass":"TursoServerlessException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Serverless.Client/HranaHttp.cs","lineNumber":32,"sourceCode":"    /// <summary>HTTP header carrying the encryption key of an encrypted Turso Cloud database.</summary>\n    internal const string EncryptionKeyHeader = \"x-turso-encryption-key\";\n\n    private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);\n\n    internal static async Task<HranaPipelineResponse> ExecutePipelineAsync(\n        HttpClient httpClient,\n        string baseUrl,\n        string? authToken,\n        string? remoteEncryptionKey,\n        HranaPipelineRequest request,\n        CancellationToken cancellationToken)\n    {\n        using var httpRequest = CreateRequest($\"{baseUrl}/v3/pipeline\", authToken, remoteEncryptionKey, request);\n\n        using var response = await httpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);\n        if (!response.IsSuccessStatusCode)\n        {\n            throw new TursoServerlessException($\"HTTP error! status: {(int)response.StatusCode}\");\n        }\n\n        var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);\n        return JsonSerializer.Deserialize<HranaPipelineResponse>(body, JsonOptions)\n            ?? throw new TursoServerlessException(\"Empty pipeline response\");\n    }\n\n    internal static async Task<(HranaCursorResponse Response, IAsyncEnumerable<HranaCursorEntry> Entries)> ExecuteCursorAsync(\n        HttpClient httpClient,\n        string baseUrl,\n        string? authToken,\n        string? remoteEncryptionKey,\n        HranaCursorRequest request,\n        CancellationToken cancellationToken)\n    {\n        var httpRequest = CreateRequest($\"{baseUrl}/v3/cursor\", authToken, remoteEncryptionKey, request);\n\n        HttpResponseMessage? response = null;","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Serverless.Client/HranaHttp.cs#L14-L50","documentation":"ExecutePipelineAsync posts the JSON pipeline to {baseUrl}/v3/pipeline and, on any non-2xx response, throws TursoServerlessException containing only the numeric HTTP status. The response body — which for Turso errors usually carries a JSON message — is not read on this path, so authentication, URL, and request-shape failures all surface as this one generic message.","triggerScenarios":"401 from a missing/invalid/expired Bearer token; 404 from a wrong baseUrl or database name; 403 from a token without access to the database; 400 from a malformed pipeline body; 5xx from server incidents; missing x-turso-encryption-key header for an encrypted database.","commonSituations":"Expired Turso auth token in CI; URL copied without the https:// scheme or with a typo'd org/database slug; environment-specific token mix-ups; encrypted database accessed without the key; gateways returning 502 during maintenance.","solutions":["Verify the URL: https://<database>-<org>.turso.io (or your libsql endpoint) with no trailing path.","Verify the auth token is present, current, and scoped to the database (turso db tokens create / show).","For encrypted databases, supply the encryption key so the x-turso-encryption-key header is set.","Reproduce with curl -H 'Authorization: Bearer <token>' -d @pipeline.json <url>/v3/pipeline to see the server's JSON error body, which this code path discards."],"exampleFix":"// before: token null or stale -> 401 -> HTTP error! status: 401\nvar conn = new TursoConnection(\"Data Source=https://db-org.turso.io;AuthToken=\");\n\n// after: load the token from the environment\nvar conn = new TursoConnection($\"Data Source=https://db-org.turso.io;AuthToken={Environment.GetEnvironmentVariable(\"TURSO_AUTH_TOKEN\")}\");","handlingStrategy":"try-catch","validationCode":"// validate endpoint and token shape before first use\nif (!Uri.TryCreate(baseUrl, UriKind.Absolute, out var u) || u.Scheme != Uri.UriSchemeHttps)\n    throw new ArgumentException(\"baseUrl must be an https:// URL\");\nif (string.IsNullOrWhiteSpace(authToken))\n    throw new InvalidOperationException(\"Auth token missing; set TURSO_AUTH_TOKEN\");","typeGuard":null,"tryCatchPattern":"catch (TursoServerlessException ex) when (ex.Message.Contains(\"status: 401\"))\n{\n    // refresh the database token and rebuild the client/connection\n}\ncatch (TursoServerlessException ex) when (ex.Message.Contains(\"status: 5\"))\n{\n    // server incident: retry with backoff\n}","preventionTips":["Load the auth token from environment/secret store at startup and fail fast when empty.","Regenerate tokens before expiry; store the database URL next to the token in config.","Smoke-test the endpoint with curl to see the JSON error body the client discards.","Supply the encryption key header for encrypted databases."],"tags":["dotnet","http","hrana-protocol","authentication","serverless"],"backgroundTag":"http-api-error-status","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}