美文网首页
AFN 展示500消息报错内容

AFN 展示500消息报错内容

作者: c2ebc00a0e48 | 来源:发表于2020-06-06 17:36 被阅读0次

    -(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:@"其他错误"];

        }

    }

    相关文章

      网友评论

          本文标题:AFN 展示500消息报错内容

          本文链接:https://www.haomeiwen.com/subject/wapgzhtx.html