Improve handling of errors #39

Open
opened 2021-04-22 12:14:52 +02:00 by Jef Roosens · 0 comments

At the moment, we just convert every type of error into a FejError object, but this approaches isn't as flexible when it comes to defining verbose error messages.

As an alternative, could define FejError like this:

pub enum FejError {
	ReqwestError(reqwest::Error),
    DatabaseError(diesel::result::Error),
}

We can then define a From<reqwest::Error> for Status for each wrapped type (reqwest::Error is just an example here). This way, we have full control over what each error represents when returning a Status.

As a bonus, we can practice writing macros, as this looks like a prime example.

Inspiration for this approach

At the moment, we just convert every type of error into a `FejError` object, but this approaches isn't as flexible when it comes to defining verbose error messages. As an alternative, could define `FejError` like this: ```rust pub enum FejError { ReqwestError(reqwest::Error), DatabaseError(diesel::result::Error), } ``` We can then define a `From<reqwest::Error> for Status` for each wrapped type (`reqwest::Error` is just an example here). This way, we have full control over what each error represents when returning a Status. As a bonus, we can practice writing macros, as this looks like a prime example. [Inspiration for this approach](https://edgarluque.com/blog/wrapping-errors-in-rust)
Jef Roosens added this to the Fej 1.1.1 milestone 2021-04-22 12:14:52 +02:00
Jef Roosens added the
enhancement
label 2021-04-22 12:14:52 +02:00
Jef Roosens self-assigned this 2021-04-22 12:14:52 +02:00
Jef Roosens added this to the Fej 1.1.1 project 2021-04-22 12:14:52 +02:00
Jef Roosens modified the milestone from Fej 1.1.1 to Fej 1.1.0 - The Calm before the Storm 2021-04-22 12:19:51 +02:00
Jef Roosens modified the project from Fej 1.1.1 to Fej 1.1.0 2021-04-22 12:19:53 +02:00
Jef Roosens added the
project/backend
label 2021-04-29 09:28:52 +02:00
Jef Roosens added a new dependency 2021-05-10 16:56:52 +02:00
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: Chewing_Bever/fej#39
There is no content yet.