Error handling with axum and enum_convert
github.com·17h·
Discuss: r/rust
Flag this post

About

This repository is an example of how I like to do error handling with axum with the help of enum_convert to avoid some repetitive From implementations.

The code implements a dummy job runner API with those few routes:

  • POST /jobs to create a job
  • GET /jobs to get the jobs list
  • GET /job/{job_id} to get a specific job
  • POST /job/{job_id}/reset to reset a job state
  • POST /job/{job_id}/cancel to cancel a job so that it does not get executed

The main idea for error handling is that each route handler has its own error type (see [CancelJobError](https://github.com/avandecreme/axum-error-example/blob/main/src/bin/axum_error_example/api/…

Similar Posts

Loading similar posts...