Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
What's the elegant way of checking an error is 404 not found
1,713 views
Skip to first unread message
David DENG
unread,
Feb 10, 2016, 12:25:59 PM
2/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
The
error
is returned by
"net/http".Client.Get
etc.
Thanks!
Tim K
unread,
Feb 10, 2016, 12:36:27 PM
2/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
From the godoc:
"A non-2xx response doesn't cause an error."
So don't expect that you will get an
error
back from
Get
for 404.
Instead check
Response.StatusCode == http.
StatusNotFound
, after you deal with the case when
error != nil
of course.
Konstantin Khomoutov
unread,
Feb 10, 2016, 12:42:13 PM
2/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to David DENG, golang-nuts
On Wed, 10 Feb 2016 09:25:59 -0800 (PST)
David DENG <
david...@gmail.com
> wrote:
> The error is returned by "net/http".Client.Get etc.
if resp.StatusCode == http.StatusNotFound {
...
}
where resp is *http.Response passed to your handler.
Reply all
Reply to author
Forward
0 new messages