Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NsError and userinfo

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?

like image 863
Kermit the Frog Avatar asked Oct 11 '13 18:10

Kermit the Frog


1 Answers

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.

like image 66
Joel Avatar answered Oct 30 '22 17:10

Joel