I am building an IOS SDK.
Basically, I am making an asynchronous network request (API Call). When there is an error, a dictionary is returned with keys "error_key", "error_description", "error_code".
How can I represent those three information using NSError?
I am doing the following:
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue: error_description forKey: NSLocalizedDescriptionKey];
[NSError errorWithDomain: APPErrorDomain code: error_code userInfo: details];
How do I change the userinfo to also take into account error_key?
If your "error_key" corresponds to one of the predefined userInfo
dictionary keys then you should add it to the userInfo
dictionary using the proper key. The defined keys are:
NSString * const NSLocalizedDescriptionKey;
NSString * const NSErrorFailingURLStringKey;
NSString * const NSFilePathErrorKey;
NSString * const NSStringEncodingErrorKey;
NSString * const NSUnderlyingErrorKey;
NSString * const NSURLErrorKey;
NSString * const NSLocalizedFailureReasonErrorKey;
NSString * const NSLocalizedRecoverySuggestionErrorKey;
NSString * const NSLocalizedRecoveryOptionsErrorKey;
NSString * const NSRecoveryAttempterErrorKey;
NSString * const NSHelpAnchorErrorKey;
NSString * const NSURLErrorFailingURLErrorKey;
NSString * const NSURLErrorFailingURLStringErrorKey;
NSString * const NSURLErrorFailingURLPeerTrustErrorKey;
If it is custom key, then you should just add it to your userInfo
dictionary with whatever key you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With