aboutsummaryrefslogtreecommitdiff
path: root/pkg/navitia_api_client/error.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-05-04 16:19:42 +0200
committerJulien Dessaux2021-05-04 16:47:07 +0200
commitd2658b5c0c7bd8c6214a8e34582cdba23da8ce0d (patch)
tree5f55025c86f7ebbb0932bc94e2e1415cbfe8f040 /pkg/navitia_api_client/error.go
parentReworked the navitia_api_client to be mockable (diff)
downloadtrains-d2658b5c0c7bd8c6214a8e34582cdba23da8ce0d.tar.gz
trains-d2658b5c0c7bd8c6214a8e34582cdba23da8ce0d.tar.bz2
trains-d2658b5c0c7bd8c6214a8e34582cdba23da8ce0d.zip
Improved navitia api error handling and testing
Diffstat (limited to '')
-rw-r--r--pkg/navitia_api_client/error.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/pkg/navitia_api_client/error.go b/pkg/navitia_api_client/error.go
new file mode 100644
index 0000000..31080de
--- /dev/null
+++ b/pkg/navitia_api_client/error.go
@@ -0,0 +1,70 @@
+package navitia_api_client
+
+import "fmt"
+
+// navitia api query error
+type ApiError struct {
+ code int
+ request string
+}
+
+func (e *ApiError) Error() string {
+ return fmt.Sprintf("Navitia Api error return code %d - %s", e.code, e.request)
+}
+
+func newApiError(code int, request string) error {
+ return &ApiError{
+ code: code,
+ request: request,
+ }
+}
+
+// http client error
+type HttpClientError struct {
+ msg string
+ err error
+}
+
+func (e *HttpClientError) Error() string { return fmt.Sprintf("Navitia HttpClient error %s", e.msg) }
+func (e *HttpClientError) Unwrap() error { return e.err }
+
+func newHttpClientError(msg string, err error) error {
+ return &HttpClientError{
+ msg: msg,
+ err: err,
+ }
+}
+
+// json decoding error
+type JsonDecodeError struct {
+ msg string
+ err error
+}
+
+func (e *JsonDecodeError) Error() string { return fmt.Sprintf("Navitia JsonDecode error %s", e.msg) }
+func (e *JsonDecodeError) Unwrap() error { return e.err }
+
+func newJsonDecodeError(msg string, err error) error {
+ return &JsonDecodeError{
+ msg: msg,
+ err: err,
+ }
+}
+
+// date parsing error
+type DateParsingError struct {
+ date string
+ err error
+}
+
+func (e *DateParsingError) Error() string {
+ return fmt.Sprintf("Navitia date parsing error %s", e.date)
+}
+func (e *DateParsingError) Unwrap() error { return e.err }
+
+func newDateParsingError(date string, err error) error {
+ return &DateParsingError{
+ date: date,
+ err: err,
+ }
+}