SpaceTradersAPI / api-docs

The API documentation for the SpaceTraders API
143 stars 36 forks source link

Missing error response schemas #26

Open JohnnyDeeee opened 1 year ago

JohnnyDeeee commented 1 year ago

The api docs don't contain any error response schemas, only successful responses.

I'm using a openapi generated typescript sdk which uses a generic ResponseError class for the errors

export declare class ResponseError extends Error {
    response: Response;
    name: "ResponseError";
    constructor(response: Response, msg?: string);
}

But this means i have to guess the schema like this

api.getMyShips()
  .then(response => console.log(response))
  .catch(async (err: ResponseError) => {
    const json = await err.response.json();
    console.error(err.message, json.error.code);
  });

Would be better if we had something like

api.getMyShips()
  .then(response => console.log(response))
  .catch((response: GetMyShips401Response) => console.log(response.error.message));

Just like GetMyShips200Response

export interface GetMyShips200Response {
    /**
     *
     * @type {Array<Ship>}
     * @memberof GetMyShips200Response
     */
    data: Array<Ship>;
    /**
     *
     * @type {Meta}
     * @memberof GetMyShips200Response
     */
    meta: Meta;
}
space-admiral commented 1 year ago

Absolutely, we'll add all the error codes as response objects in the schema.