Skip to content

Commit

Permalink
chore(services): use more specific error format
Browse files Browse the repository at this point in the history
  • Loading branch information
mgramigna committed Dec 23, 2023
1 parent 3d7222f commit f57796e
Show file tree
Hide file tree
Showing 32 changed files with 113 additions and 76 deletions.
3 changes: 1 addition & 2 deletions packages/api/src/router/patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const createPatientRouter = ({ patientService }: { patientService: Patien
});

if (result.isErr()) {
// TODO
throw new Error(result.error);
throw new Error(`[${result.error.errorType}] - ${result.error.details}`);
}

return result.value;
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/allergen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const AllergenService = ({ baseUrl }: { baseUrl: string }): AllergenServi
};

const create: AllergenServiceType['create'] = async () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: AllergenServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: AllergenServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/careplan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const CarePlanService = ({ baseUrl }: { baseUrl: string }): CarePlanServi
};

const create: CarePlanServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: CarePlanServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: CarePlanServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/careteam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const CareTeamService = ({ baseUrl }: { baseUrl: string }): CareTeamServi
};

const create: CareTeamServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: CareTeamServiceType['update'] = async ({ resource, accessToken }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/services/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ClaimServiceType = Service<Claim, never, never, Claim, never>;

export const ClaimService = ({ baseUrl }: { baseUrl: string }): ClaimServiceType => {
const read: ClaimServiceType['read'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const create: ClaimServiceType['create'] = async ({ resource, accessToken }) => {
Expand All @@ -22,11 +22,11 @@ export const ClaimService = ({ baseUrl }: { baseUrl: string }): ClaimServiceType
};

const update: ClaimServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ClaimServiceType['search'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CommunicationService = ({
};

const update: CommunicationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: CommunicationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ConsentService = ({ baseUrl }: { baseUrl: string }): ConsentService
};

const update: ConsentServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ConsentServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/services/coverageeligibilityrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const CoverageEligibilityRequestService = ({
baseUrl: string;
}): CoverageEligibilityRequestServiceType => {
const read: CoverageEligibilityRequestServiceType['read'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const create: CoverageEligibilityRequestServiceType['create'] = async ({
Expand All @@ -35,11 +35,11 @@ export const CoverageEligibilityRequestService = ({
};

const update: CoverageEligibilityRequestServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: CoverageEligibilityRequestServiceType['search'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/services/coverageeligibilityresponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const CoverageEligibilityResponseService = ({
baseUrl: string;
}): CoverageEligibilityResponseServiceType => {
const read: CoverageEligibilityResponseServiceType['read'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const create: CoverageEligibilityResponseServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: CoverageEligibilityResponseServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: CoverageEligibilityResponseServiceType['search'] = async ({
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export const DeviceService = ({ baseUrl }: { baseUrl: string }): DeviceServiceTy
};

const create: DeviceServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: DeviceServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: DeviceServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/diagnosticreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const DiagnosticReportService = ({
};

const create: DiagnosticReportServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: DiagnosticReportServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: DiagnosticReportServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/documentreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const DocumentReferenceService = ({
};

const create: DocumentReferenceServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: DocumentReferenceServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: DocumentReferenceServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/encounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const EncounterService = ({ baseUrl }: { baseUrl: string }): EncounterSer
};

const create: EncounterServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: EncounterServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: EncounterServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export const GoalService = ({ baseUrl }: { baseUrl: string }): GoalServiceType =
};

const create: GoalServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: GoalServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: GoalServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/immunization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const ImmunizationService = ({ baseUrl }: { baseUrl: string }): Immunizat
};

const create: ImmunizationServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: ImmunizationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ImmunizationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const LocationService = ({ baseUrl }: { baseUrl: string }): LocationServi
};

const create: LocationServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: LocationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: LocationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const MediaService = ({ baseUrl }: { baseUrl: string }): MediaServiceType
};

const update: MediaServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: MediaServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/medication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const MedicationService = ({ baseUrl }: { baseUrl: string }): MedicationS
};

const create: MedicationServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: MedicationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: MedicationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/medicationrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const MedicationRequestService = ({
};

const create: MedicationRequestServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: MedicationRequestServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: MedicationRequestServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/observation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ObservationService = ({ baseUrl }: { baseUrl: string }): Observatio
};

const update: ObservationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ObservationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const OrganizationService = ({ baseUrl }: { baseUrl: string }): Organizat
};

const create: OrganizationServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: OrganizationServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: OrganizationServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/src/services/paymentnotice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const PaymentNoticeService = ({
};

const update: PaymentNoticeServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: PaymentNoticeServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/practitioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const PractitionerService = ({ baseUrl }: { baseUrl: string }): Practitio
};

const create: PractitionerServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: PractitionerServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: PractitionerServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const ProcedureService = ({ baseUrl }: { baseUrl: string }): ProcedureSer
};

const create: ProcedureServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: ProcedureServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ProcedureServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/provenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const ProvenanceService = ({ baseUrl }: { baseUrl: string }): ProvenanceS
};

const create: ProvenanceServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: ProvenanceServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ProvenanceServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/src/services/questionnaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const QuestionnaireService = ({
};

const create: QuestionnaireServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: QuestionnaireServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: QuestionnaireServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/services/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export type ScheduleServiceType = Service<

export const ScheduleService = ({ baseUrl }: { baseUrl: string }): ScheduleServiceType => {
const read: ScheduleServiceType['read'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const create: ScheduleServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: ScheduleServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: ScheduleServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/services/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export type SlotServiceType = Service<Slot, SlotSearchArgs, SlotBundle, never, n

export const SlotService = ({ baseUrl }: { baseUrl: string }): SlotServiceType => {
const read: SlotServiceType['read'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const create: SlotServiceType['create'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const update: SlotServiceType['update'] = () => {
return Promise.resolve(err('NOT_SUPPORTED'));
return Promise.resolve(err({ errorType: 'UNSUPPORTED' }));
};

const search: SlotServiceType['search'] = async ({ accessToken, args }) => {
Expand Down
Loading

0 comments on commit f57796e

Please sign in to comment.