Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fix: add routing for 409 errors #109

Merged
merged 4 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"cors": "^2.8.5",
"errorhandler": "^1.5.1",
"express": "^4.17.1",
"fhir-works-on-aws-interface": "^9.0.0",
"fhir-works-on-aws-interface": "^9.1.0",
"flat": "^5.0.0",
"http-errors": "^1.8.0",
"lodash": "^4.17.15",
Expand Down
6 changes: 6 additions & 0 deletions src/router/routes/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IssueSeverity,
IssueCode,
isInvalidSearchParameterError,
isResourceConflictError,
} from 'fhir-works-on-aws-interface';
import OperationsGenerator from '../operationsGenerator';

Expand Down Expand Up @@ -43,13 +44,18 @@ export const applicationErrorMapper = (
next(new createError.BadRequest(err.message));
return;
}
if (isResourceConflictError(err)) {
next(new createError.Conflict(err.message));
return;
}
next(err);
};

const statusToOutcome: Record<number, { severity: IssueSeverity; code: IssueCode }> = {
400: { severity: 'error', code: 'invalid' },
403: { severity: 'error', code: 'security' },
404: { severity: 'error', code: 'not-found' },
409: { severity: 'error', code: 'conflict' },
500: { severity: 'error', code: 'exception' },
};

Expand Down