If the API responds with an error, the program will panic because it fails to deserialize the response, it doesn’t ever expect an error.
Solution
We could deserialize responses into an enum with an error variant and non-error variant. The non-error variant should probably take in a generic which will be the struct expected for a successful request.
Alternatives
We could possibly use the pre-existing Result enum and create a custom error struct, but I’m not sure if we can deserialize into Result.
Problem
If the API responds with an error, the program will panic because it fails to deserialize the response, it doesn’t ever expect an error.
Solution
We could deserialize responses into an enum with an error variant and non-error variant. The non-error variant should probably take in a generic which will be the struct expected for a successful request.
Alternatives
We could possibly use the pre-existing
Result
enum and create a custom error struct, but I’m not sure if we can deserialize intoResult
.