For users of tika.Client it can be useful to be able to differentiate between intermittent errors (http status code 500) and content related errors (e.g. 415 and 422) however currently the client methods just return an opaque error string.
diff --git a/tika/tika.go b/tika/tika.go
index a6ffdab..8a0cd39 100644
--- a/tika/tika.go
+++ b/tika/tika.go
@@ -29,6 +29,16 @@ import (
"golang.org/x/net/context/ctxhttp"
)
+// ClientError represents an error response from the Tika server.
+type ClientError struct {
+ // StatusCode is the http status code returned by the Tika server.
+ StatusCode int
+}
+
+func (e ClientError) Error() string {
+ return fmt.Sprintf("response code %d", e.StatusCode)
+}
+
// Client represents a connection to a Tika Server.
type Client struct {
// url is the URL of the Tika Server, including the port (if necessary), but
@@ -107,7 +117,7 @@ func (c *Client) call(ctx context.Context, input io.Reader, method, path string,
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("response code %v", resp.StatusCode)
+ return nil, ClientError{resp.StatusCode}
}
return ioutil.ReadAll(resp.Body)
}
For users of
tika.Client
it can be useful to be able to differentiate between intermittent errors (http status code 500) and content related errors (e.g. 415 and 422) however currently the client methods just return an opaque error string.I'm experimenting in my fork https://github.com/tomyl/go-tika with exposing the http status code in the error. Basically:
The calling code can do something like
Thoughts? I'm happy to submit a PR if a change like this would be accepted.