【发布时间】:2013-11-12 12:37:00
【问题描述】:
在普通的 Go HTTP 处理程序上,如果我在写入响应的同时断开客户端连接,http.ResponseWritter.Write 将返回错误消息,如write tcp 127.0.0.1:60702: connection reset by peer。
现在来自syscall 包,我有sysca.ECONNRESET,其中有消息connection reset by peer,所以它们并不完全相同。
我怎样才能匹配它们,所以我知道如果发生它不要惊慌?在我一直在做的其他场合
if err == syscall.EAGAIN {
/* handle error differently */
}
例如,效果很好,但我无法使用 syscall.ECONNRESET。
更新:
因为我迫切需要一个解决方案,所以我暂时将做这个非常肮脏的黑客:
if strings.Contains(err.Error(), syscall.ECONNRESET.Error()) {
println("it's a connection reset by peer!")
return
}
【问题讨论】:
标签: error-handling go runtime-error