Coder Social home page Coder Social logo

jfoster / go-ves Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 20 KB

Golang client for the GOV.UK DVLA Vehicle Enquiry API

Home Page: https://developer-portal.driver-vehicle-licensing.api.gov.uk/apis/vehicle-enquiry-service/v1.1.0-vehicle-enquiry-service.html#vehicle-enquiry-api

License: MIT License

Go 100.00%
api-client dvla go golang govuk rest-client vehicle-enquiry-service

go-ves's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @jfoster
  • ๐Ÿ‘€ Iโ€™m interested in ...
  • ๐ŸŒฑ Iโ€™m currently learning ...
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on ...
  • ๐Ÿ“ซ How to reach me ...

go-ves's People

Contributors

jfoster avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-ves's Issues

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.