Skip to content

4. Error Handling

Chabardes edited this page May 11, 2022 · 20 revisions

As we said in the previous chapter, we don't check much in the command handler. Does the Hero exists ? Does the Item exists ? Does the Item being equipped belongs to the Hero ?

At Libeo, we use the neverthrow library. The goal is to explicitly tell what could go wrong in our handlers. You can find more information on how we handle our backend errors in the Notion documentation.

  1. Create a HeroDoesNotOwnItem Error.
  2. Create a EquipItemCommandResult with a neverthrow Result and explicit the expected errors.
  3. Use the decorators @WrapInTryCatchWithUnknownApplicationError and @LogPayloadAndResult to catch and log any unexpected errors.
  4. Update the command handler to return the EquipItemCommandResult.

Last commit

Clone this wiki locally