# All files / common/files/multer multer.utils.ts

100% Statements 9/9
90.91% Branches 10/11
100% Functions 1/1
100% Lines 9/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    211x
    1x

    1x
    6x
    2x

    4x

    1x

    1x

    2x

     import { BadRequestException, HttpException, PayloadTooLargeException } from '../../exceptions';
    import { multerExceptions } from './multer.constants';

    export function transformException(error: Error | undefined) {
      if (!error || error instanceof HttpException) {
        return error;
      }
      switch (error.message) {
        case multerExceptions.LIMIT_FILE_SIZE:
          return new PayloadTooLargeException(error.message);
        case multerExceptions.LIMIT_FILE_COUNT:
        case multerExceptions.LIMIT_FIELD_KEY:
        case multerExceptions.LIMIT_FIELD_VALUE:
        case multerExceptions.LIMIT_FIELD_COUNT:
        case multerExceptions.LIMIT_UNEXPECTED_FILE:
        case multerExceptions.LIMIT_PART_COUNT:
          return new BadRequestException(error.message);
      }
      return error;
    }