Error handling is a little cumbersome
rburchell opened this issue · comments
Thanks for the useful library.
Some feedback, from the perspective of someone who is relatively new to both Flickr and Go:
The returned error objects are more or less useless - telling me "an error happened but I have no idea why, go ask someone else for the information" seems obtuse as it makes robust handling of errors significantly longer than the already fairly verbose form Go requires (constant if err != nil { /* handle */). I did some patching which, I think, made things a lot easier to work with:
diff --git a/response.go b/response.go
index c7312a3..18e2f07 100644
--- a/response.go
+++ b/response.go
@@ -86,7 +86,9 @@ func parseApiResponse(res *http.Response, r FlickrResponse) error {
}
if r.HasErrors() {
- return flickErr.NewError(10)
+ err := flickErr.NewError(flickErr.ApiError)
+ err.Message += r.ErrorMsg()
The errors still lack the capability to communicate common conditions (such as "no such user") but at least the message is now helpful by default.
You're absolutely right.
If you want to open a PR I'll be more than happy to merge so you get credit for the fix, or I can apply the patch manually. Anyway, thanks for your feedback!