如何从`MoyaError`获取错误statusCode?(How to get error statusCode from `MoyaError`?)

我正在使用MoyaMoya_ModelMapperRxSwift来执行网络请求。 这是我的示例代码:

let provider = RxMoyaProvider<MyEndpoint>()
let observable: Observable<RegistrationResponse> = provider.request(.register(firstName: "", lastName: "", email: "", password: "")).mapObject(type: RegistrationResponse.self)
observable.subscribe {
    [weak self] (event: Event<RegistrationResponse>) in
    switch event {
    case .next(let response):
        print(response)
    case .error(let error):
        print(error)
    case .completed:
        break
    }
}

一切工作正常,但我不知道如何从服务器收到例如409状态码响应类型时得到错误代码。 如果我打印错误,我会得到:

jsonMapping(Status Code: 409, Data Length: 0)

但我不知道如何通过代码获取此状态码。 错误是MoyaError ,它是一个Enum类型。 这里是MoyaError的源代码

谢谢!


I'm using a Moya, Moya_ModelMapper and RxSwift to perform network requests. Here is my example code:

let provider = RxMoyaProvider<MyEndpoint>()
let observable: Observable<RegistrationResponse> = provider.request(.register(firstName: "", lastName: "", email: "", password: "")).mapObject(type: RegistrationResponse.self)
observable.subscribe {
    [weak self] (event: Event<RegistrationResponse>) in
    switch event {
    case .next(let response):
        print(response)
    case .error(let error):
        print(error)
    case .completed:
        break
    }
}

Everything works fine, but I don't know how to get an error code when I receive for example a 409 status code response type from the server. If I print the error I will get:

jsonMapping(Status Code: 409, Data Length: 0)

but I don't know how to get this status code by code. The error is MoyaError which is an Enum type. Here it's a source code of MoyaError.

Thanks!


原文:https://stackoverflow.com/questions/41911565
2023-05-08 22:05

满意答案

试试这个,希望它有效

<div class="container">
  <div class="row">
    <div class="col-md-3 br">
      <div class="row">
        <div class="col-md-12">s</div>
        <div class="col-md-12">s</div>
      </div>
    </div>

    <div class="col-md-9 br" style="height:700px">aaa</div>
  </div>
</div>

Try this, Hope it works

<div class="container">
  <div class="row">
    <div class="col-md-3 br">
      <div class="row">
        <div class="col-md-12">s</div>
        <div class="col-md-12">s</div>
      </div>
    </div>

    <div class="col-md-9 br" style="height:700px">aaa</div>
  </div>
</div>

相关问答

更多

清除Bootstrap DatePicker值(Clear Bootstrap DatePicker Value)

如果#birthday包含#birthday ,请执行此操作,它将起作用: $('#clearButton').on('click', function() { alert('Clear the value in the "birthday" field...'); $('#birthday').data("DateTimePicker").clear(); }); 您需要在$('#birthday').data("DateTimePicker")对象上调用clear 。 这...

如何清除bootstrap中响应div之间的边距(How to clear margins between responsive divs in bootstrap)

它们不是边距,它是填充,你可以使用padding: 0px删除它padding: 0px你的col-* div上的padding: 0px 。 They are not margins, it is padding, and you can remove it using padding: 0px on your col-* divs.

在PHP中的一定数量的DIV之后插入清除修复(Insert Clear Fix After Certain Amount of DIVs in PHP)

试试这个它将检查3的倍数并放置一个clearfix div 也不要忘记从1到$ i <= $ numberOfArticles启动$ i $featured_articles = get_field('featured_articles', false, false ); $id = $featured_articles[0]; //var_dump(); $numberOfArticles = count($featured_articles); //var_du...

标题div高度不计算,'清除修复'不工作?(header div height not calculating, 'clear fix' not working?)

通过删除position: absolute;来固定position: absolute; 来自.logo 。 标题保持为空,因为其中的每个子项都以不同的方式定位为静态或相对。 如果他们是.header的直接孩子,漂浮可能是问题 It is fixed by removing the position: absolute; from .logo. You header stays empty because every child inside it has been positioned in ...

div下面的Bootstrap div(Bootstrap div below div)

原因是你在你的包装元素上使用top: 100px 。 在MDN上排名第一 : ...对于相对定位的元素,如果元素未定位,则元素在正常流程中移动到其位置以下的偏移量。 这意味着当您移动#wrapper时, #wrapper #below保留在同一个地方,就像您没有使用top 。 要解决此问题,您可以使用margin-top: 100px代替,这不会改变#wrapper的正常流程。 The reason being is you are using top: 100px on your wrapper...

Bootstrap:如何清除图库中的图像?(Bootstrap: how to clear images in a gallery?)

它破坏的原因是你为每个第三个图像创建一个新row 。 # # # 会打破 # # # 然后下一个图像再次出现在新行中: # # # # 将所有图像放在一行中,它们将根据您为每个图像设置的字体进行打破。 The reason it breaks is the fact that you create a new row for every third image. # # # will break to # # # And then the next image is within a ...

Bootstrap div清除修复(Bootstrap div clear fix)

试试这个,希望它有效 <div class="container"> <div class="row"> <div class="col-md-3 br"> <div class="row"> <div class="col-md-12">s</div> <div class="col-md-12">s</div> </div> </div> <div class="col-md-9 br" style="hei...

在Bootstrap中修复页脚(Fix footer in Bootstrap)

.instructables-container { margin-top: 25px; margin-bottom: 300px; margin-left: 0px; letter-spacing: 2px; line-height: 2; font-size: 15px; font-family: Helvetica; } .table{ margin-top: 80px; text-align:...

如何在使用bootstrap滚动时修复一些div?(How to fix some divs on top while scrolling using bootstrap?)

为了达到你的目标,你需要使用position: fixed和z-index: 1030 CSS与你的div 这是jsfiddle 在你的div中使用这个CSS <div id="filters" class="container-fluid" style="margin-top: 60px; position: fixed; z-index: 1030;"> <div class="row"> <div class="col-md-2 col-sm-4"> ...

如何使用bootstrap修复菜单(How to fix menu using bootstrap)

您可以选择以下两个选项: 使菜单项中的文本更短。 使文本左侧和右侧的填充更小。 但最终只有一个适合一个菜单行的东西。 对于选项2,您将不得不更改CSS文件。 添加如下内容: .navbar-inverse .navbar-nav > li > a { padding: 5px 10px; } 或者在您的环境中有效的任何变体。 检查样式以查看您需要更改的内容。 You can choose between these two options: Make the texts in the men...

相关文章

更多

eclipse里报:An internal error occurred during:

eclipse里报:An internal error occurred during: Buildi ...

The connection to adb is down, and a severe error has occured.

启动android模拟器时.有时会报The connection to adb is down, an ...

solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias

在solr中 添加新的索引词语时,报如标题所示错误,指定是插入的字段没有在solr索引字段里 可以修改 ...

Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'

解决方法安装Solr过程出现错误,报异常 org.apache.solr.common.SolrExc ...

error C2668: 'M' : ambiguous call to overloaded function

以下是代码: #include&lt;iostream&gt;using namespace std ...

win8安装VirtualBox-4.2.18提示Installation failed!error:系统找不到指定的路径

在win8上安装VirtualBox-4.2.4-81684-Win.exe,提示Installati ...

Hadoop 异常记录 ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times

当我把Hadoop、hbase安装配置(具体参考这里)好了之后,启动hbase的shell交互模式,输 ...

命令行运行Hbase: Session 0x0 for server null, unexpected error

又重新看了下hbase的操作,以前虽说是运行过对Hbase的操作,比如直接的建表,导入数据,或者是使用 ...

solr 4.4 Error filterStart 问题

纠结了很久的问题,https://wiki.apache.org/solr/SolrLogging#U ...

[Hadoop] Error: JAVA_HOME is not set

在namenode启动脚本%Hadoop_HOME%/bin/start-dfs.sh的时候发现dat ...

最新问答

更多

您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)

将diff文件复制到存储库的根目录,然后执行以下操作: git apply yourcoworkers.diff 有关apply命令的更多信息, apply 见其手册页 。 顺便说一下:一个更好的方法是通过文件交换整个提交文件是发送者上的命令git format-patch ,然后在接收器上加上git am ,因为它也传送作者信息和提交信息。 如果修补程序应用程序失败,并且生成diff的提交实际上在您的备份中,则可以使用尝试在更改中合并的apply程序的-3选项。 它还适用于Unix管道,如下

将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)

尝试将第二行更改为snprintf(buf1, sizeof buf1, "%.2f", balance1); 。 另外,为什么要声明用该特定表达式分配缓冲区的存储量? EDIT @LưuVĩnhPhúc在下面的评论中提到我的原始答案中的格式说明符将舍入而不是截断,因此根据如何在不使用C舍入的情况下截断小数,您可以执行以下操作: float balance = 200.56866; int tmp = balance1 * 100; float balance1 = tmp / 100.0; c

OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)

这是简单的解决方案 在你需要写的控制器中 BackendMenu::setContext('Archetypics.Team', 'website', 'team'); 请参阅https://octobercms.com/docs/backend/controllers-views-ajax#navigation-context BackendMenu::setContext('Author.Plugin name', 'Menu code', 'Sub menu code'); 你需要在r

页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)

每当发出请求时ASP都会创建一个新的Page对象,并且一旦它将响应发送回用户就不会保留对该Page对象的引用,因此只要你找不到某种方法来保持生命自己引用该Page对象后,一旦发送响应, Page和只能通过该页面访问的所有对象才有资格进行垃圾回收。 ASP creates a new Page object whenever a request is made, and it does not hold onto the reference to that Page object once it

codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)

要在生产服务器中调试这个,你可以临时放 error_reporting(E_ALL); 并查看有哪些其他错误阻止正确的重定向。 您还应该检查生产服务器发送的响应标头。 它是否具有“缓存”,是否需要重新验证标头等 to debug this in production server, you can temporary put error_reporting(E_ALL); and see what other errors are there that prevents the proper

在计算机拍照在哪里进入

打开娥的电脑.在下面找到视频设备点击进去就可以了...

使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)

你是对的。 第一次输入后,换行符将保留在输入缓冲区中。 第一次读取后尝试插入: cin.ignore(); // to ignore the newline character 或者更好的是: //discards all input in the standard input stream up to and including the first newline. cin.ignore(numeric_limits::max(), '\n'); 您必须为#inc

No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)

for (int k = 0; k > 10; k++) { System.out.println(k); } k不大于10,所以循环将永远不会执行。 我想要什么是k<10 ,不是吗? for (int k = 0; k < 10; k++) { System.out.println(k); } for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop

单页应用程序:页面重新加载(Single Page Application: page reload)

优点是不注销会避免惹恼用户,以至于他们会想要杀死你:-)。 说真的,如果每次刷新页面时应用程序都会将我注销(或者在新选项卡中打开一个链接),我再也不会使用该应用程序了。 好吧,不要这样做。 确保身份验证令牌存储在刷新后的某个位置,即不在某些JS变量中,而是存储在cookie或本地存储中。 The advantage is that not logging off will avoid pissing off your users so much that they'll want to kill

在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)

EXECUTE IMMEDIATE 'SELECT '||field_val_temp ||' FROM tableb WHERE function_id = :func_val AND rec_key = :rec_key' INTO field_val USING 'STDCUSAC' , yu.rec_key; 和, EXECUTE IMMEDIATE 'UPDATE tablec SET field_val_'||i||' = :field_val' USI