From 57b6e99211346081ed1cafdf670499aa8bbddb5f Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Fri, 15 Aug 2025 16:30:05 +0200 Subject: [PATCH] refactor: modernize MulterError to ES6 class --- lib/multer-error.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/multer-error.js b/lib/multer-error.js index d56b00e8..8069387c 100644 --- a/lib/multer-error.js +++ b/lib/multer-error.js @@ -1,6 +1,4 @@ -var util = require('util') - -var errorMessages = { +const errorMessages = { LIMIT_PART_COUNT: 'Too many parts', LIMIT_FILE_SIZE: 'File too large', LIMIT_FILE_COUNT: 'Too many files', @@ -11,14 +9,13 @@ var errorMessages = { MISSING_FIELD_NAME: 'Field name missing' } -function MulterError (code, field) { - Error.captureStackTrace(this, this.constructor) - this.name = this.constructor.name - this.message = errorMessages[code] - this.code = code - if (field) this.field = field +class MulterError extends Error { + constructor (code, field) { + super(errorMessages[code]) + this.name = this.constructor.name + this.code = code + if (field) this.field = field + } } -util.inherits(MulterError, Error) - module.exports = MulterError