Set proper HTTP status code in write_error()