首页 \ 问答 \ 处理API错误与网络错误(Handling API errors vs Network errors)

处理API错误与网络错误(Handling API errors vs Network errors)

我正在构建SDK。

基本上,开发人员传入一个错误的Handler函数,该函数将在进行API调用时发生错误。

对于API错误(或API返回的错误),我使用域ExampleAPPDomain创建NSError。 ApI错误具有不同的userInfo结构(例如,我向用户信息添加“类别”键)。

但有时错误是nsurlconnection错误...我也将该错误传递给错误处理程序。

所以我打电话给:

errorHandler(error)

有时传递给errorHandler函数的NSError错误是API错误,有时它是NSUrlConnection类型错误(如网络错误)。

我怎样才能更好地处理这些错误? 例如,在错误处理程序代码中,开发人员必须检查域中的错误,以查看它的类型(NSURLDomain与ExampleAPPDomain)并相应地处理它。 这是两种错误之间不同的唯一方法。

处理APP错误与NSUrlConnection连接错误的标准方法是什么?


I am building an SDK.

Basically developers pass in a error Handler function that will be called with the error that occurs when making an API call.

For API errors (or errors returned by the API), I create an NSError with domain ExampleAPPDomain. ApI Errors have a different userInfo structure (I add a "category" key to the user info, for example).

But sometimes the error is a nsurlconnection error ... I also pass that error to the error handler.

so I call:

errorHandler(error)

sometimes the NSError error passed into errorHandler function is an API error and sometimes it is a NSUrlConnection type error (like a network error).

How can I best handle those errors differently? For example, in the error handler code, developers would have to check the domain for the Error to see what type it is (NSURLDomain vs ExampleAPPDomain) and handle it accordingly. That is the only way to differently between both errors.

What is the standard way of handling APP errors vs NSUrlConnection connected errors for something like this?


原文:https://stackoverflow.com/questions/19389869
更新时间:2022-09-26 17:09

最满意答案

jQuery('.text').animate({
                'right': '300px',
            }, 'slow', 'linear').animate({
                'left': '300px'
            }, 'slow', 'linear').animate({
                'left': '0',
                'right': '0',
            });
    jQuery('.text').css('right', 'auto')
    jQuery('.text').css('left', 'auto')
});

工作演示: http//jsfiddle.net/UCTgR/12/ (注意:这个演示有部分功能你只是显示你错过了什么,检查点击横幅)


jQuery('.text').animate({
                'right': '300px',
            }, 'slow', 'linear').animate({
                'left': '300px'
            }, 'slow', 'linear').animate({
                'left': '0',
                'right': '0',
            });
    jQuery('.text').css('right', 'auto')
    jQuery('.text').css('left', 'auto')
});

working demo : http://jsfiddle.net/UCTgR/12/ (Note: this demo has partial functionality yo just show what u missed, to check click on the banner)

相关问答

更多
  • 怎么样 - http://jsfiddle.net/ZhUx8/1/ 。 jQuery(function($) { $('.topnav li').find('a[href]').parent().each(function() { var li = $(this), a = li.find('a'), div = $('
    ' + '<\/div>'); li.hover(function() { ...
  • 我找到了一些插件。 他们都用mousedown来划伤图像,否则我认为他们接近你要找的东西。 它不应该很难改变为mousedown的行为,并使其自动循环。 http://rabidflash.com/authoring/codecanyon/scratch/ http://www.senamion.com/blog/2010/03/30/jquery-jscratchcard-scratchcard-effect-on-image/ http://www.htmldrive.net/items/demo/88 ...
  • 我认为做出以下改变将实现你想要的。 如果不正确,请提供更多详细信息。 setInterval(function() { gradient_percent -= speed; if (gradient_percent < gradient_offset.min) { gradient_percent = gradient_offset.max; } JSFiddle 。 I think making the following change will achieve ...
  • 你的意思是这样吗? http://jqueryui.com/demos/draggable/#revert 只需将还原选项设置为true: $("#b1").draggable({ revert: true }); You mean like this? http://jqueryui.com/demos/draggable/#revert Just set the revert option to true: $("#b1").draggable({ revert: true });
  • jQuery('.text').animate({ 'right': '300px', }, 'slow', 'linear').animate({ 'left': '300px' }, 'slow', 'linear').animate({ 'left': '0', 'right': '0', }); ...
  • 这是基本的jQuery,你做的大部分内容看似正确..你只需要定位你找到的ID ...然后添加类... jQuery(document).ready(function($) { $('.rating-button').click(function(e){ e.preventDefault(); var form = $(this).find('form'); var id = form.attr('id'); $(id).addCla ...
  • 您还需要使用jQuery UI库... 你们两个: //ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js //ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js 不只是 //ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js 代码应该看起来像