Custom Errors Based on Response Body with Alamofire #3849
Unanswered
naiadelali
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Alamofire team and community,
I'm new to Swift development and I'm working on a project where I extensively use Alamofire for network requests. I've come across a need to implement a more specific and granular error handling system that differentiates errors based on HTTP response codes and the specific content of the response body.
Specifically, I'm looking to learn how to generate custom errors for different HTTP status codes, such as 400 and 401, including details like the exception name, detailed messages based on the response body, and the URL that was accessed when the error occurred.
For example, for responses with status code 400, I would like to create a custom error that includes details like below:
400
And for status code 401, a custom error that provides the following response:
401
I'm seeking guidance or examples on how I can effectively implement this functionality using Alamofire, so that I can reuse the code for various types of errors and responses. My goal is to improve the error handling system in my application, providing users with clear and detailed feedback about the issues encountered during their network requests.
As I'm beginning with Swift and Alamofire, any advice or pointers towards resources, examples, or best practices for achieving this would be greatly appreciated.
Thank you in advance for any help or direction you can provide.
My code:
@jshier
Beta Was this translation helpful? Give feedback.
All reactions