【问题标题】:Internal Server Error on callback post回调帖子的内部服务器错误
【发布时间】:2018-06-15 22:32:55
【问题描述】:

我正在尝试测试登录帖子,端点存在并且正常,但响应始终是错误的。 详细信息:请求未在我的端点中命中,因此错误 500 不是我的后端错误。 细节 2:在 chrome 的网络选项卡中,请求没有出现。

错误返回:

body:Object {error: "Object(...) is not a function"}
headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: }
status:500
statusText:"Internal Server Error"
url:"http://localhost:8080/"

我的代码是:

login(user, onsuccess?, onerror?): void {
    let url: string = `${this.BASE_URL}/`;
    this.httpClient.post(url, user, { headers: this.headers }).subscribe(
      response => {
        this.setLogin("test");
        if (onsuccess) {
          onsuccess(response);
        }
      },
      error => {
        this.setLogin("test");
        if (onerror) {
          onerror(error);
        }
      },
    );
  }

怎么了?

【问题讨论】:

    标签: javascript angular typescript httprequest


    【解决方案1】:

    内部服务器错误状态:500 是服务器端错误。

    这意味着服务器用于连接数据库的凭据可能有问题,抛出异常,或者您发送到路由的参数不正确。

    仅凭前端代码,无法确定是哪一个。

    【讨论】:

    • 我的 api 中没有命中请求。
    • 尝试使用 POSTMAN 或 SOAPUI 进行 POST 调用
    • 它命中了 some API,它返回了 500。如果它没有命中预期的端点,那么你在某处错误地定义了目标。也许它不应该是localhost:8080,而是一些外部网络服务器?
    • 请求未触发,未出现在我的网络选项卡中,并且我的端点未收到任何请求
    【解决方案2】:

    我发现了问题...

    import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
    
    InMemoryWebApiModule.forRoot(TestMock, {
           passThruUnknownUrl: true
         }
    

    我在某些情况下使用模拟来模拟 api,但这会导致问题并避免我的真实请求被触发。

    【讨论】:

      猜你喜欢
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      相关资源
      最近更新 更多