// // NSError+RQExtension.m // RQCommon // // Created by 张嵘 on 2018/11/23. // Copyright © 2018 张嵘. All rights reserved. // #import "NSError+RQExtension.h" // The domain for errors originating from RQModel. static NSString * const RQModelErrorDomain = @"RQModelErrorDomain"; // An exception was thrown and caught. static const NSInteger RQModelErrorExceptionThrown = 1; // Associated with the NSException that was caught. static NSString * const RQModelThrownExceptionErrorKey = @"RQModelThrownException"; @implementation NSError (RQExtension) + (instancetype)rq_modelErrorWithException:(NSException *)exception { NSParameterAssert(exception != nil); NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: exception.description, NSLocalizedFailureReasonErrorKey: exception.reason, RQModelThrownExceptionErrorKey: exception }; return [NSError errorWithDomain:RQModelErrorDomain code:RQModelErrorExceptionThrown userInfo:userInfo]; } + (NSString *)rq_tipsFromError:(NSError *)error{ if (!error) return nil; NSString *tipStr = nil; /// 这里需要处理HTTP请求的错误 if (error.domain) { tipStr = error.localizedFailureReason; } else { tipStr = error.localizedDescription; } return tipStr; } @end