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

Commit

Permalink
fix: add routing for 409 errors (#109)
Browse files Browse the repository at this point in the history
* fix: implement routing for 409 errors

* update fhir-works-on-aws-interface package to access ResourceConflictError
  • Loading branch information
ssvegaraju authored Aug 6, 2021
1 parent 0c9d81b commit 27c80ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 27c80ea

Please sign in to comment.