airlock's People
airlock's Issues
[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)
[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:
- Handling of error status codes: Currently, the
typescript-fetch
generator throws aResponseError
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. - Typed error objects: Ideally, we want the error objects to be typed. However, those types are not currently available in the OpenAPI SpaceTraders spec.
- Accessing the error response: Since the package uses Fetch, the error response can be accessed by calling
response.json()
. The generator's runtime handlesresponse.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);
});
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.