Code Monkey home page Code Monkey logo

airlock's People

Contributors

jonchurch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

airlock's Issues

[Fetch] Throws Response Error on http failure

Handling Errors in @spacejunk/airlock

This issue is for tracking a few concerns related to error handling in the @spacejunk/airlock package while using Fetch as the http client:

  1. Handling of error status codes: Currently, the typescript-fetch generator throws a ResponseError for status codes above 299, which is a departure from the pure Fetch behavior. This choice is not intentional but is imposed by the generator's source, which still needs to be located.
  2. Typed error objects: Ideally, we want the error objects to be typed. However, those types are not currently available in the OpenAPI SpaceTraders spec.
  3. Accessing the error response: Since the package uses Fetch, the error response can be accessed by calling response.json(). The generator's runtime handles response.json() for successful requests, so it's unexpected for users to have this magic removed for error responses.

Here's sample TypeScript code to illustrate the error handling:

import { Configuration, FleetApi, ResponseError } from '../dist';

export const config = new Configuration({
  accessToken: 'NO_TOKEN',
});

// Fails if there is NO_TOKEN, but also fails with a real token because the shipSymbol is nonsense
const badRequest = async () => {
  const fleet = new FleetApi(config);
  const res = await fleet.getShipCooldown('asdfasdfasa');
  if (res) {
    return res.data;
  }
  return undefined;
};

badRequest()
  .then((result) => console.log('Result from fulfilled promise:', result))
  .catch(async (err: ResponseError) => {
    const { response } = err;
    console.log('Full response', response);
    console.log('JSON body:', await response.json());
    console.log('status:', response.status);
  });

[openapi] Set the User Agent header to airlock

There is a configuration option for the generator [--http-user-agent <http user agent>]

I should figure out how/if to set that for the client library.

I'd likely do @spacejunk/airlock, would be great to have the version number in there too.

I could go super verbose with
@spacejunk/[email protected] (Node.js; TypeScript; https://github.com/jonchurch/airlock)

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.