reply: func(w http.ResponseWriter) {
conn, _, err := http.NewResponseController(w).Hijack()
if err == nil {
- _ = conn.Close()
+ // This forced disconnect has no
+ // response or retry after close.
+ conn.Close() // nolint: errcheck
}
},
retry: true,
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusTooManyRequests)
- _, _ = io.WriteString(w, `{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 3","parameters":{"retry_after":3}}`)
+ _, err := io.WriteString(w, `{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 3","parameters":{"retry_after":3}}`)
+ if err != nil {
+ panic(err)
+ }
},
retry: true,
wait: 3 * time.Second,
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadGateway)
- _, _ = io.WriteString(w, "<html>bad gateway</html>")
+ _, err := io.WriteString(w, "<html>bad gateway</html>")
+ if err != nil {
+ panic(err)
+ }
},
retry: true,
errorText: "502 Bad Gateway",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusUnauthorized)
- _, _ = io.WriteString(w, `{"ok":false,"error_code":401,"description":"Unauthorized: bot`+telegramTestToken+`"}`)
+ _, err := io.WriteString(w, `{"ok":false,"error_code":401,"description":"Unauthorized: bot`+telegramTestToken+`"}`)
+ if err != nil {
+ panic(err)
+ }
},
retry: false,
errorText: "Unauthorized: botTOKEN",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadRequest)
- _, _ = io.WriteString(w, `{"ok":false,"error_code":400,"description":"Bad Request: can't parse"}`)
+ _, err := io.WriteString(w, `{"ok":false,"error_code":400,"description":"Bad Request: can't parse"}`)
+ if err != nil {
+ panic(err)
+ }
},
retry: false,
rejected: true,
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
- _, _ = io.WriteString(w, `{"ok":false,"error_code":404,"description":"Not Found"}`)
+ _, err := io.WriteString(w, `{"ok":false,"error_code":404,"description":"Not Found"}`)
+ if err != nil {
+ panic(err)
+ }
},
retry: false,
rejected: true,
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
- _, _ = io.WriteString(w, "<html>not found</html>")
+ _, err := io.WriteString(w, "<html>not found</html>")
+ if err != nil {
+ panic(err)
+ }
},
retry: false,
errorText: "404 Not Found",
{
name: "broken answer is retried",
reply: func(w http.ResponseWriter) {
- _, _ = io.WriteString(w, `{"ok":`)
+ _, err := io.WriteString(w, `{"ok":`)
+ if err != nil {
+ panic(err)
+ }
},
retry: true,
errorText: "invalid JSON",
return
}
- _, _ = w.Write(data)
+ // The client can cancel a media request before this reply is
+ // written.
+ w.Write(data) // nolint: errcheck
return
}
wait = 1
}
- _, _ = fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":%d}}`, status, description, wait)
+ // A test can cancel the request after the handler selects its
+ // reply.
+ fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":%d}}`, status, description, wait) // nolint: errcheck
return
}
f.record(call)
if method == "getFile" {
- _ = json.NewEncoder(w).Encode(map[string]any{
+ // A cancelled client does not need a response body.
+ json.NewEncoder(w).Encode(map[string]any{ // nolint: errcheck
"ok": true,
"result": map[string]any{"file_path": params["file_id"]},
})
}
if method != "getUpdates" {
- _, _ = io.WriteString(w, `{"ok":true,"result":true}`)
+ // A cancelled client does not need a response body.
+ io.WriteString(w, `{"ok":true,"result":true}`) // nolint: errcheck
+
return
}
updates = f.from(offset)
}
- _ = json.NewEncoder(w).Encode(map[string]any{
+ // A cancelled client does not need a response body.
+ json.NewEncoder(w).Encode(map[string]any{ // nolint: errcheck
"ok": true,
"result": updates,
})