Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Chrome在控制台中显示错误,尽管错误处理是在函数中定义的_Javascript_Google Chrome_Error Handling_Console_Httpresponse - Fatal编程技术网

Javascript Google Chrome在控制台中显示错误,尽管错误处理是在函数中定义的

Javascript Google Chrome在控制台中显示错误,尽管错误处理是在函数中定义的,javascript,google-chrome,error-handling,console,httpresponse,Javascript,Google Chrome,Error Handling,Console,Httpresponse,我有以下函数,它从Google Analytics API请求数据,并以JSON数组的形式获得响应: // Query the Core Reporting API from Google Analytics with the defined variables function requestResponse() { gapi.client.analytics.data.ga.get({ 'ids': 'ga:' + $('input[name="hiddenProfileId

我有以下函数,它从Google Analytics API请求数据,并以JSON数组的形式获得响应:

// Query the Core Reporting API from Google Analytics with the defined variables

function requestResponse() {

  gapi.client.analytics.data.ga.get({
    'ids': 'ga:' + $('input[name="hiddenProfileId"]').val(),
    'start-date': $('input[name="hiddenStartDate"]').val(),
    'end-date': $('input[name="hiddenEndDate"]').val(),
    'metrics': metricsArrayOutput.join(","),
    'dimensions': dimensionsArrayOutput.join(",")

// If response isn't an error, then change div background to pale green and show a "Tree View" of the JSON obtained
  }).then(function(response) {
    $("#responseOutput").empty();
    $("#responseOutput").JSONView(response.result, {collapsed: true});
    $("#responseOutput").css("background-color", "#bef7be");

// Handle error: change div background to pale red and show the error Objects of the JSON obtained
  }, function(errorResponse) {
    $("#responseOutput").empty();
    $("#responseOutput").JSONView(errorResponse.result.error, {collapsed: false});
    $("#responseOutput").css("background-color", "#FBDDDD");
    alert("bad things happen to everyone");
  })
}
这是我第一次使用then()方法,虽然一开始我在处理错误响应时遇到了一些问题(因为最初我只定义了success case的参数),但现在它工作得非常好,我喜欢处理所有非200 HTTP响应的简单性

然而,在Google Chrome(v.47.0.2526.106)控制台中,当响应不是200 HTTP响应时,我收到一个奇怪的“GET错误”:

得到 ?{parameters_,该_导致_错误_响应} 400(好的)

{parameters_the_result_in_error_response}是发送到生成错误响应的API的变量组合

正如我所说的,这个函数可以工作,它的总体目标已经实现,但是我不明白为什么会出现这个错误。当http响应为200时,不会向控制台发送任何内容,因此我可以想象.then()会将此错误发送到控制台本身,尽管在几行之后的代码中会对其进行处理。你知道如何解决这种不协调吗


注意:IE或Firefox中没有显示错误。

这就是google chrome开发工具的工作原理,它在控制台中显示http错误。@jcubic thx以获取注释。对我来说,直到现在,一个干净、无错误的控制台是一个好代码的总称。我相信我必须改变我的假设:)