dongshen4129 2017-04-13 21:06
浏览 232

client.Do错误获取状态码[关闭]

When I call client.Do method, how would I be notified for errors like 429 response code (aka too many requests). Should I expect to get a response object back with a status code 429 or will I get an error with just the message “too many requests”?

I am seeing the latter and what I need is to be able to get status code for all errors (server/dial/tcp/dns/etc.) and successes and only in some cases I can get the actual code in case of errors. Is there anyway to get all response codes irrespective of the error type - the error message seems to reflect the details but would still like to get the code if possible.

  • 写回答

1条回答 默认 最新

  • douzhi19900102 2017-04-13 22:32
    关注

    The http documentation covers this very clearly.

    Of particular interest are the documentation for Do:

    An error is returned if caused by client policy (such as CheckRedirect), or failure to speak HTTP (such as a network connectivity problem). A non-2xx status code doesn't cause an error.

    (Emphasis added)

    And the documentation for the Response object returned by Do:

    type Response struct {
        Status     string // e.g. "200 OK"
        StatusCode int    // e.g. 200
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程