Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 4.76.2 #1221

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.76.1"
".": "4.76.2"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 4.76.2 (2024-12-12)

Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)

### Chores

* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))

## 4.76.1 (2024-12-10)

Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openai/openai",
"version": "4.76.1",
"version": "4.76.2",
"exports": "./index.ts",
"publish": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openai",
"version": "4.76.1",
"version": "4.76.2",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <support@openai.com>",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,8 @@ export const safeJSON = (text: string) => {
}
};

// https://stackoverflow.com/a/19709846
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
Expand Down
64 changes: 24 additions & 40 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ import { castToError, Headers } from './core';

export class OpenAIError extends Error {}

export class APIError extends OpenAIError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;
export class APIError<
TStatus extends number | undefined = number | undefined,
THeaders extends Headers | undefined = Headers | undefined,
TError extends Object | undefined = Object | undefined,
> extends OpenAIError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
readonly headers: THeaders;
/** JSON body of the response that caused the error */
readonly error: TError;

readonly code: string | null | undefined;
readonly param: string | null | undefined;
readonly type: string | undefined;

readonly request_id: string | null | undefined;

constructor(
status: number | undefined,
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
super(`${APIError.makeMessage(status, error, message)}`);
this.status = status;
this.headers = headers;
this.request_id = headers?.['x-request-id'];
this.error = error;

const data = error as Record<string, any>;
this.error = data;
this.code = data?.['code'];
this.param = data?.['param'];
this.type = data?.['type'];
Expand Down Expand Up @@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
message: string | undefined,
headers: Headers | undefined,
): APIError {
if (!status) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}

Expand Down Expand Up @@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
}
}

export class APIUserAbortError extends APIError {
override readonly status: undefined = undefined;

export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

export class APIConnectionError extends APIError {
override readonly status: undefined = undefined;

export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
Expand All @@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

export class BadRequestError extends APIError {
override readonly status: 400 = 400;
}
export class BadRequestError extends APIError<400, Headers> {}

export class AuthenticationError extends APIError {
override readonly status: 401 = 401;
}
export class AuthenticationError extends APIError<401, Headers> {}

export class PermissionDeniedError extends APIError {
override readonly status: 403 = 403;
}
export class PermissionDeniedError extends APIError<403, Headers> {}

export class NotFoundError extends APIError {
override readonly status: 404 = 404;
}
export class NotFoundError extends APIError<404, Headers> {}

export class ConflictError extends APIError {
override readonly status: 409 = 409;
}
export class ConflictError extends APIError<409, Headers> {}

export class UnprocessableEntityError extends APIError {
override readonly status: 422 = 422;
}
export class UnprocessableEntityError extends APIError<422, Headers> {}

export class RateLimitError extends APIError {
override readonly status: 429 = 429;
}
export class RateLimitError extends APIError<429, Headers> {}

export class InternalServerError extends APIError {}
export class InternalServerError extends APIError<number, Headers> {}

export class LengthFinishReasonError extends OpenAIError {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '4.76.1'; // x-release-please-version
export const VERSION = '4.76.2'; // x-release-please-version
Loading