# Go: http: superfluous response.WriteHeader call from main.handler (main.go:25)

**Code:** `http: superfluous response.WriteHeader call` · **Category:** Go · **Seen on:** Go

A handler wrote the status header more than once, or wrote the body first (which sends 200) and then tried to set another status.

## Meaning

The first `Write` implicitly sends status 200. Calling `WriteHeader` or `http.Error` afterwards is ignored and logged. Return after sending an error, and set status/headers before writing the body.

## Common causes

- http.Error followed by more writes
- Missing return after writing an error response
- WriteHeader called after Write
- Middleware and handler both writing
- Calling WriteHeader twice

## Quick fix

1. `return` immediately after `http.Error(...)`
2. Call `w.WriteHeader(code)` before any `w.Write`
3. Avoid writing from middleware after the handler

## Detailed fix by platform

### Go

1. `if err != nil { http.Error(w, err.Error(), 500); return }`

## How to diagnose

1. **Order** — Header before body?
2. **Return** — After errors?
3. **Writers** — Multiple layers?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/http-superfluous-writeheader)
