Skip to content

VES API Has inconsistent error responses which are currently throw a nil pointer #1

@Mentioum

Description

@Mentioum

Currently any errors which come back from the VES API are unmarshalled into the following struct:

type ErrorResponse struct {
	Errors []Error `json:"errors"`
}

type Error struct {
	Status Status `json:"status,omitempty"`
	Code   Status `json:"code,omitempty"`
	Title  string `json:"title"`
	Detail string `json:"detail,omitempty"`
}

Unfortunately the VES API isn't so consistent. When Supplying the following test registration number ER19THR as documented in the Test API response document it is supposed to return a 429 Too Many Requests

What it actually returns:

{
    "message": "Too Many Requests"
}

This obviously fails to unMarshal into the ErrorResponse type and actually causes a nil pointer exception when the array is nil in func Do as shown below:

func (r *Request) Do(v interface{}) (*http.Response, error) {
	if r.e != nil {
		return nil, r.e
	}

	resp, err := r.c.httpClient.Do(r.Request)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		var errResp ErrorResponse
		err := json.NewDecoder(resp.Body).Decode(&errResp)
		if err != nil {
			return resp, err
		}
		return resp, errResp.Errors[0]
	}

I suggest creating a custom unmarshalling function for ErrorResponse which accounts for the VES API's inconsistencies.

Will make a PR when we get around to fixing it on our end if you don't fix it before us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions