Skip to content

Commit

Permalink
fix: don't log non-enumerable error properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kukhariev committed Nov 11, 2022
1 parent dbdfaf2 commit 16ef6f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/handlers/base-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export abstract class BaseHandler<TFile extends UploadxFile>
handle = (req: http.IncomingMessage, res: http.ServerResponse): void => this.upload(req, res);

upload = (req: http.IncomingMessage, res: http.ServerResponse, next?: () => void): void => {
req.on('error', err => this.logger.error(`[request error]: %o`, err));
req.on('error', err => this.logger.error(`[request error]: %O`, err));
this.cors.preflight(req, res);
this.logger.debug(`[request]: %s %s`, req.method, req.url);
const handler = this.registeredHandlers.get(req.method as string);
Expand Down Expand Up @@ -178,7 +178,7 @@ export abstract class BaseHandler<TFile extends UploadxFile>
]) as UploadxError;
const errorEvent = { ...err, request: pick(req, ['headers', 'method', 'url']) };
this.listenerCount('error') && this.emit('error', errorEvent);
this.logger.error('[error]: %o', errorEvent);
this.logger.error('[error]: %O', errorEvent);
if ('aborted' in req && req['aborted']) return;
return this.sendError(res, error);
});
Expand Down Expand Up @@ -226,9 +226,9 @@ export abstract class BaseHandler<TFile extends UploadxFile>
sendError(res: http.ServerResponse, error: Error): void {
const httpError = isUploadxError(error)
? this._errorResponses[error.uploadxErrorCode]
: !isValidationError(error)
? this.storage.normalizeError(error)
: error;
: isValidationError(error)
? error
: this.storage.normalizeError(error);
const response = this.storage.onError(httpError);
this.send(res, response);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storages/disk-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class DiskStorage extends BaseStorage<DiskFile> {
}
this.accessCheck().catch(err => {
this.isReady = false;
this.logger.error('[error]: Could not write to directory: %o', err);
this.logger.error('[error]: Could not write to directory: %O', err);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storages/local-meta-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class LocalMetaStorage<T extends File = File> extends MetaStorage<T> {
super(config);
this.directory = (config?.directory || join(tmpdir(), 'uploadx_meta')).replace(/\\/g, '/');
this.accessCheck().catch(err => {
this.logger.error('[error]: Could not write to directory: %o', err);
this.logger.error('[error]: Could not write to directory: %O', err);
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class BasicLogger implements Logger {

write = (data: unknown[], level: Exclude<LogLevel, 'none'>): void => {
if (PriorityOf[level] >= PriorityOf[this._logLevel]) {
const message = formatWithOptions({ colors: true, depth: 1, maxStringLength: 80 }, ...data);
const message = formatWithOptions({ depth: 1, maxStringLength: 80 }, ...data);
const timestamp = new Date().toISOString();
this.logger[level](`${timestamp} ${level.toUpperCase()} ${this.label} ${message}`);
}
Expand All @@ -77,4 +77,4 @@ export class BasicLogger implements Logger {
}
}

export const logger = new BasicLogger({});
export const logger = new BasicLogger();
4 changes: 2 additions & 2 deletions packages/gcs/src/gcs-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class GCStorage extends BaseStorage<GCSFile> {

this.accessCheck().catch((err: ClientError) => {
this.isReady = false;
this.logger.error('Unable to open bucket: %o', err);
this.logger.error('Unable to open bucket: %O', err);
});
}

Expand Down Expand Up @@ -230,7 +230,7 @@ export class GCStorage extends BaseStorage<GCSFile> {
return range ? getRangeEnd(range) : 0;
} else if (res.ok) {
const data = (await res.json()) as Record<string, any>;
this.logger.debug('uploaded %o', data);
this.logger.debug('uploaded %O', data);
return size;
}
const message = await res.text();
Expand Down
2 changes: 1 addition & 1 deletion packages/s3/src/s3-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class S3Storage extends BaseStorage<S3File> {
}
this.accessCheck().catch((err: AWSError) => {
this.isReady = false;
this.logger.error('Unable to open bucket: %o', err);
this.logger.error('Unable to open bucket: %O', err);
});
}

Expand Down

0 comments on commit 16ef6f0

Please sign in to comment.