---
title: "Go proxy: log 503, hide the body"
category: "code"
id: f24da21c-919d-4986-8824-130b2c08f421
canonical: https://solvedlist.com/solutions/go-proxy-log-503-hide-the-body
---

# Go proxy: log 503, hide the body

> Go proxy solution to log upstream HTTP 503 status while returning a fixed public error, with testing approach

## Question

handle HTTP 503 upstream error in Go proxy to preserve status for debugging while keeping body private and test both outputs

## Solution

Keep the upstream body out of the error value, log attributes and client reply. For an upstream HTTP failure, log a fixed event and the numeric upstream status. Return a fixed public error. The caller closes response.Body.

```go
package upstreamerrors

import (
	"io"
	"log/slog"
	"net/http"
)

func writeUpstreamFailure(w http.ResponseWriter, logger *slog.Logger, response *http.Response) {
	logger.Error("upstream request failed", "upstream_status", response.StatusCode)
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusBadGateway)
	io.WriteString(w, "{\"code\":\"upstream_failed\",\"message\":\"Service temporarily unavailable.\"}\n")
}
```

Test with a fake 503 response containing a unique marker. Capture the client body and structured log output. Assert 502 and the fixed public message, a log with upstream_status=503, and zero marker matches in both outputs. Use the same fixed-category approach for JSON decode failures.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
