AFN 展示500消息报错内容

2020-06-06  本文已影响0人  c2ebc00a0e48

-(void)outError:(NSError*)errorandUrlStr:(NSString*)urlStr{

   // NSString *domain = error.domain;

//服务器报错信息

    NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];

//服务器报错响应头

       NSHTTPURLResponse*reoponseData  =  error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey];

//其他错误 404或者其它

    if(!errorData ||!reoponseData) {

        [MBProgressHUDshowError:@"网络错误"];

        return;

    }

//格式化服务器报错信息

    NSDictionary*serializedData = [NSJSONSerializationJSONObjectWithData: errorDataoptions:kNilOptionserror:nil];

    if([serializedDataisKindOfClass:[NSDictionaryclass]]&&[reoponseDataisKindOfClass:[NSHTTPURLResponseclass]]) {

            NSString*data = [serializedDataobjectForKey:@"data"];

        NSString*errStr = [NSStringstringWithFormat:@"---请求失败----\nurlString:%@ \n code:%ld \nInfo:%@",urlStr,reoponseData.statusCode,data];

            //  NSLog(@"---请求失败--- domain:%@----code:%ld ---Info:%@", domain ,reoponseData.statusCode,data);

         [MBProgressHUDshowError:errStr];

       }

    else{

         [MBProgressHUDshowError:@"其他错误"];

    }

}

上一篇 下一篇

猜你喜欢

热点阅读