fix:
- AES GCM protocol mismatch - better, granular error handling - UUID now uses crypto.randomUUID() - added native mlock addon to improve security - ZeroBuffer uses explicit_bzero now - fixed imports feat: - added unit tests
This commit is contained in:
parent
0b09b9a9c3
commit
c7601b2270
17 changed files with 12600 additions and 164 deletions
|
|
@ -2,6 +2,9 @@
|
|||
* Error classes matching OpenAI's error structure
|
||||
*/
|
||||
|
||||
// V8-specific stack trace capture (not in standard TS types)
|
||||
const captureStackTrace = (Error as unknown as { captureStackTrace?: (t: object, c: Function) => void }).captureStackTrace;
|
||||
|
||||
export class APIError extends Error {
|
||||
statusCode?: number;
|
||||
errorDetails?: object;
|
||||
|
|
@ -12,9 +15,8 @@ export class APIError extends Error {
|
|||
this.statusCode = statusCode;
|
||||
this.errorDetails = errorDetails;
|
||||
|
||||
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
if (captureStackTrace) {
|
||||
captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,13 +49,27 @@ export class ServerError extends APIError {
|
|||
}
|
||||
}
|
||||
|
||||
export class ForbiddenError extends APIError {
|
||||
constructor(message: string, statusCode?: number, errorDetails?: object) {
|
||||
super(message, statusCode, errorDetails);
|
||||
this.name = 'ForbiddenError';
|
||||
}
|
||||
}
|
||||
|
||||
export class ServiceUnavailableError extends APIError {
|
||||
constructor(message: string, statusCode?: number, errorDetails?: object) {
|
||||
super(message, statusCode, errorDetails);
|
||||
this.name = 'ServiceUnavailableError';
|
||||
}
|
||||
}
|
||||
|
||||
export class APIConnectionError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'APIConnectionError';
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
if (captureStackTrace) {
|
||||
captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -63,8 +79,8 @@ export class SecurityError extends Error {
|
|||
super(message);
|
||||
this.name = 'SecurityError';
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
if (captureStackTrace) {
|
||||
captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue