【问题标题】:How to fake error 504 in node-express server如何在 node-express 服务器中伪造错误 504
【发布时间】:2019-04-11 20:41:44
【问题描述】:

我想检查我编写的代码,它在发生错误 504 时重试请求(仅一次)。有人可以帮助我如何伪造错误来检查它吗? (服务器是Node express,客户端是AngularJs)。

旧代码是:

this.update = function(endpoint, body, config) {
        return $http.put(endpoint, body, config || {});
    };

我的新代码是:

this.update = function(endpoint, body, config) {
        var updateRequest = $http.put(endpoint, body, config || {}). catch(function (error) {
            if (error.status === 504){
                return $http.put(endpoint, body, config || {});
            }
        });

        return updateRequest;
    };

谢谢!

【问题讨论】:

    标签: angularjs node.js http express request


    【解决方案1】:

    $http.put 中的timeout 选项提供0 值。

    this.update = function(endpoint, body, config) {
           var timeoutConfig = Object.assign({},config);
               timeoutConfig.timeout = 0; // provide the time in millisecond for waiting
            var updateRequest = $http.put(endpoint, body, timeoutConfig || {}). catch(function (error) {
                if (error.status === 504){
                    return $http.put(endpoint, body, config || {});
                }
            });
    
            return updateRequest;
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 2023-02-16
      • 2015-09-28
      相关资源
      最近更新 更多