失敗の経路は2つあります。業務の失敗(予約が存在しない、取得した時点で予約が来院済みではない状態不正、保存の時点で競合した)は、利用者が次の操作を選べるため、Err で返します。障害(データベースの障害、破損データ)は、同期のコードでは例外、非同期のコードでは reject として発生し、利用者が次の操作を選べないため、Err に変えずに外側へ渡します。
値がワークフローを流れる
場面1「競合: 業務の失敗の経路」
- 前のページの成功の流れと、
storeを呼ぶまでは同じです。ここでstoreはerrでAppointmentConflictを返します。業務で発生しうる失敗であるため、型に残ります。 andThroughはErrを次へ渡し、最後のmapは実行されません。- 呼び出し元の route が
Errを受け取り、/?notice=conflictへの 303 リダイレクトに変換します。獣医師の画面には、次の通知が表示されます。
場面2「保存障害: 例外の経路」
- 前のページの成功の流れと、
storeを呼ぶまでは同じです。ここで SQLite の書き込みが失敗すると、storeのResultAsyncの内側の Promise が reject します。OkにもErrにもならず、型に残りません。 - 最後の
mapは実行されず、reject はResultの経路の外へ出ます。外側で 500 を返し、詳細は含めません。保存先の障害をErrの型に追加しないため、route が分岐する失敗は業務の失敗のままです。
examples/
resolveAppointment(deps)(input.appointmentId) 実行されない
Ok AppointmentState | undefined { kind: "CheckedIn", … }
.andThen(ensureFound(input.appointmentId)) 実行されない
Ok Appointment { kind: "CheckedIn", … }
.andThen(ensureCheckedIn) 実行されない
Ok CheckedIn { kind: "CheckedIn", … }
.map(startExaminationEvent(deps, input.veterinarianId)) 実行されない
Ok ExaminationStarted { kind: "ExaminationStarted", … }
.andThrough(deps.examinationStartedStore.store) 実行されない
Ok ExaminationStarted { kind: "ExaminationStarted", … }
Err AppointmentConflict { kind: "AppointmentConflict", … }
reject AppointmentPersistenceError append-audit の
examinationStartedStore.ts:186-188
ResultAsync. fromSafePromise(
Promise.resolve(). then(() => storeAtomically(event)),
). andThen((result) => result), .map((event) => event.aggregateState); 実行されない
Ok InExamination { kind: "InExamination", … }
examples/
error.kind === "AppointmentConflict"
? "conflict"
: toStartExaminationNoticeCode(error); 実行されない
応答 Response 303 /?notice=conflict
獣医師の画面
操作のお知らせ
予約が
examples/
app. onError((_error, context) => context. text("Internal Server Error", 500)); 実行されない
応答 Response 500 Internal Server Error
右の札は、その行から次の行へ渡される値です。札「Ok」は成功の Result です。札「応答」は呼び出し元へ返す HTTP の応答です。
札「Err」は型に残る業務の失敗で、枠と線は破線です。札「reject」は型に残らず外へ出る例外で、枠と線は実線です。