Giter Site home page Giter Site logo

coreygriffin / go-freshservice Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 48 KB

An unofficial Go API client for the Freshservice API

Home Page: https://api.freshservice.com/

License: MIT License

Makefile 2.56% Go 97.44%
api freshservice freshservice-api go golang

go-freshservice's People

Contributors

coreygriffin avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

rk295 veltorg

go-freshservice's Issues

[BUG]: HTTP or API errors are not available in any way

Version

v0.0.2

Endpoint

Any endpoint. I've tried Agent and Announcement

Expected Behavior

When running queries with invalid API credentials or bad request payloads, I would expect there to be some HTTP error returned (400, 401, 403, 404, etc) and sometimes a response body describing what went wrong. I've tried creating, listing and fetching individual entities, and it seems like in each case the HTTP error code and the error body is swallowed up internally in go-freshservice and is never available to me.

Actual Behavior

List queries return an empty slice [], while individual queries return nil. No errors are returned.

Steps to Reproduce

ctx := context.Background()

// I should get a 404 error here
api, err := fs.New(ctx, "fakedomain.freshservice.com", "badApikey", nil)
if err != nil {
    log.Fatal(err)
}
agents, _, agentsError := api.Agents().List(ctx, nil)

// agents is []
// agentsError is nil

Thoughts

This lack of access to HTTP error codes or error bodies almost seems to be by design when I take a look at the source code.

Even if the ErrorResponse interface is used conditionally in makeRequest to decode the response body, we always return &res.Details or &res.List in the query functions like Agents().List. Thus, the fields from ErrorResponse, namely Description and Errors are never used for anything and are simply discarded. The HTTP response status code is also never returned from makeRequest so that is definitely not available to me.

The existence of the ErrorResponse interface clearly indicates that HTTP errors, or at least freshservice API errors, are supposed to be handled somehow. But I'm not seeing how that can be done the way the queries are written today.

Is there something here I have misunderstood or is the codebase simply at such an early stage that error handling was never prioritised and every query is assumed to run successfully?

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.