workos-node icon indicating copy to clipboard operation
workos-node copied to clipboard

Documenting API errors

Open monolithed opened this issue 11 months ago • 3 comments

Could you please add detailed information to the API documentation about all possible errors, their meanings, and how to handle them? At the moment, understanding the differences between invalid_jwt, invalid_session_cookie, and no_session_cookie_provided requires digging into the code. Additionally, some errors, like invalid_grant, seem to come from external sources and aren't documented in the codebase.

Current:

export declare class GenericServerException extends Error implements RequestException {
    readonly status: number;
    readonly rawData: unknown;
    readonly requestID: string;
    readonly name: string;
    readonly message: string;
    constructor(status: number, message: string | undefined, rawData: unknown, requestID: string);
}

Expected:

type Organization = {
    id: string;
    name: string;
};


type Code = 'organization_selection_required' | 'no_session_cookie_provided' ...

type User = {
    object: string;
    id: string;
    email: string;
    email_verified: boolean;
    first_name: string | null;
    last_name: string | null;
    profile_picture_url: string | null;
    last_sign_in_at: string;
    created_at: string;
    updated_at: string;
    external_id: string | null;
};

type RawData = {
    code: Code;
    message: string;
    pending_authentication_token: string;
    user: User;
    organizations: Organization[];
};

type GenericServerException = {
    status: number;
    rawData: RawData;
    requestID: string;
    name: string;
    message: string;
};

monolithed avatar Jan 12 '25 07:01 monolithed

It would be nice to know if GenericServerException, OauthException etc. can be 'leaked' to the client

kevinmitch14 avatar Jan 21 '25 17:01 kevinmitch14

@kevinmitch14, they can https://github.com/workos/workos-node/issues/1202 🙂

monolithed avatar Jan 21 '25 20:01 monolithed

I mean is it safe to expose these on the client!

kevinmitch14 avatar Jan 22 '25 14:01 kevinmitch14