Declare Ktor failures with Spine and Arrow¶
Spine provides helper functions for the Arrow Typed Errors library. They are based on the Raise DSL and context parameters, which you may need to enable.
Declaring failures¶
Declaring failures with the Arrow compatibility modules is identical to declaring failures with the base Spine module. Read the dedicated article.
Server-side¶
Add a dependency on the server-arrow module:
When declaring routes, replace route by routeWithRaise:
the Arrow module adds:
The DSL is identical to usual Spine, but adds support for Raise for failure management.
For example, you can replace:
by:
Raise in Ktor endpoints without Spine
If you want to use the Raise DSL with Ktor, but don't want to use Spine, you can use our module server-arrow-independent which adds the function raise to regular Ktor endpoints.
Client-side¶
Add a dependency on the client-arrow module:
In addition to .bodyOrThrow(), .bodyOrNull() and .handle() (learn more), this module adds the .body() function which raises each failure.