Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/boydjohnson/tide-errors


https://github.com/boydjohnson/tide-errors

Last synced: 11 days ago
JSON representation

Awesome Lists containing this project

README

        

# tide-errors
If `preroll` errors are too prescriptive for you, but you don't want to write boilerplate to convert errors into JSON errors.

Convert `Result` into `Result, E2>` where `Message: Into>`

Bring your own JSON Error type, or use the default error message.

## Example

Use the default JSON errors.

```rust
convert!(db::create_some_object(...).await, ok => Message::created, DatabaseConstraintConversion::<(), UniqueConstraint>::default(), DatabaseConstraintConversion::<(), ForeignKeyConstraint>::default())
```

Use your own JSON error

```rust
let options = MyOptions::new(...);

convert!(db::create_some_object(...).await, ok => Message::created, DatabaseConstraintConversion::<_, UniqueConstraint>::with_options(options.clone()), DatabaseConstraintConversion::<_, ForeignKeyConstraint>::with_options(options))
```