When a user enters a form with invalid inputs, such as an invalid email address, then we want our UI to tell the user what went wrong.
We can pass information about invalid inputs to the frontend by using return someValue:
throw Abort(someValue)
We can use throw Abort(someValue) instead of return someValue:
In general, we recommend using return { someValue } instead of throw Abort(someValue) because:
It makes the code's intent clearer: the reader of our code knows that return someValue is an expected case that will be handled by the frontend, whereas when throwing an error it isn't obvious whether/where/how the error will be handled by the frontend.
return someValue has better TypeScript DX, as TypeScript doesn't typecheck catched errors: