donovanhide/eventsource — pull request #8 by suin (2014-08-02 01:36:19+00:00)
Title: stream: make it possible to handle errors based on HTTP response

This is a pull request to make `Subscribe` possible to handle errors based on HTTP response.

This is the example code to handle errors:

```go
_, err = eventsource.Subscribe("http://127.0.0.1:8080/stream", "")
if err != nil {
if serr, ok := err.(eventsource.SubscriptionError); ok {
fmt.Printf("Status code: %d\n", serr.Code)
fmt.Printf("Message: %s\n", serr.Message)
} else {
fmt.Println("failed to subscribe")
}
}

// Output:
// Status code: 500
// Message: Something wrong.
```

I have sent the other PR about this feature as [#7] a few days ago, but that's approach was different from this and that contains unnecessary commits. So now I send this as another PR :-)

[#7]: https://github.com/donovanhide/eventsource/pull/7