From d2658b5c0c7bd8c6214a8e34582cdba23da8ce0d Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 4 May 2021 16:19:42 +0200 Subject: Improved navitia api error handling and testing --- pkg/navitia_api_client/error.go | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 pkg/navitia_api_client/error.go (limited to 'pkg/navitia_api_client/error.go') 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, + } +} -- cgit v1.2.3