-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathhttp-error-mapper-configuration.js
54 lines (52 loc) · 2.11 KB
/
http-error-mapper-configuration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { HttpErrors } from '../../../shared/application/http-errors.js';
import { DomainErrorMappingConfiguration } from '../../../shared/application/models/domain-error-mapping-configuration.js';
import {
ChallengeToBeDeneutralizedNotFoundError,
ChallengeToBeNeutralizedNotFoundError,
InvalidSessionSupervisingLoginError,
SessionAlreadyFinalizedError,
SessionAlreadyPublishedError,
SessionNotAccessible,
SessionWithAbortReasonOnCompletedCertificationCourseError,
SessionWithMissingAbortReasonError,
SessionWithoutStartedCertificationError,
} from '../domain/errors.js';
const sessionDomainErrorMappingConfiguration = [
{
name: SessionWithoutStartedCertificationError.name,
httpErrorFn: (error) => new HttpErrors.BadRequestError(error.message, error.code, error.meta),
},
{
name: SessionWithAbortReasonOnCompletedCertificationCourseError.name,
httpErrorFn: (error) => new HttpErrors.ConflictError(error.message, error.code, error.meta),
},
{
name: SessionWithMissingAbortReasonError.name,
httpErrorFn: (error) => new HttpErrors.ConflictError(error.message, error.code),
},
{
name: SessionAlreadyFinalizedError.name,
httpErrorFn: (error) => new HttpErrors.ConflictError(error.message, error.code),
},
{
name: SessionAlreadyPublishedError.name,
httpErrorFn: (error) => new HttpErrors.BadRequestError(error.message, error.code),
},
{
name: ChallengeToBeDeneutralizedNotFoundError.name,
httpErrorFn: (error) => new HttpErrors.NotFoundError(error.message, error.code),
},
{
name: ChallengeToBeNeutralizedNotFoundError.name,
httpErrorFn: (error) => new HttpErrors.NotFoundError(error.message, error.code),
},
{
name: SessionNotAccessible.name,
httpErrorFn: (error) => new HttpErrors.PreconditionFailedError(error.message, error.code),
},
{
name: InvalidSessionSupervisingLoginError.name,
httpErrorFn: (error) => new HttpErrors.UnauthorizedError(error.message, error.code),
},
].map((domainErrorMappingConfiguration) => new DomainErrorMappingConfiguration(domainErrorMappingConfiguration));
export { sessionDomainErrorMappingConfiguration };