diff --git a/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.spec.ts b/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.spec.ts new file mode 100644 index 00000000000..22f2a851ea6 --- /dev/null +++ b/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.spec.ts @@ -0,0 +1,26 @@ +import { H5pError } from '@lumieducation/h5p-server'; +import { HttpException, InternalServerErrorException } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; +import { H5PErrorMapper } from './h5p-error.mapper'; + +describe('H5PErrorMapper', () => { + let h5pErrorMapper: H5PErrorMapper; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + providers: [H5PErrorMapper], + }).compile(); + + h5pErrorMapper = app.get(H5PErrorMapper); + }); + + describe('mapH5pError', () => { + it('should map H5pError to HttpException', () => { + const error = new H5pError('h5p error massage'); + const result = h5pErrorMapper.mapH5pError(error); + + expect(result).toBeInstanceOf(HttpException); + expect(result.message).toEqual('h5p error massage'); + }); + }); +}); diff --git a/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts b/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts index c5bdf4469a7..1cd69875985 100644 --- a/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts +++ b/apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts @@ -1,13 +1,8 @@ import { H5pError } from '@lumieducation/h5p-server'; -import { HttpException, InternalServerErrorException } from '@nestjs/common'; +import { HttpException } from '@nestjs/common'; export class H5PErrorMapper { public mapH5pError(error: H5pError) { - if (error instanceof H5pError) { - return new HttpException(error.message, error.httpStatusCode); - } - return new HttpException('message', 500, { - cause: new InternalServerErrorException({ error }), - }); + return new HttpException(error.message, error.httpStatusCode); } }