簡體   English   中英

如何在Ember應用程序中處理來自服務器的503響應?

[英]How to Handle 503 Response from Server in Ember Application?

如何在我的ember應用程序中處理來自服務器的503響應? 如何作為UI開發人員進行調試? UI Developer如何處理這些類型的響應。

ember提供了默認的error handlers ,當找到相應的錯誤子狀態時將觸發該error handlers

例如:如果路徑的model掛鈎返回error有效負載(來自服務器的錯誤響應),則可以處理錯誤事件並用於顯示錯誤消息,重定向到頁面等。

import Route from '@ember/routing/route';

export default Route.extend({
  model(params) {
    return this.store.findAll('privileged-model');
  },

  actions: {
    error(error, transition) {
      if (error.status === '403') {
        this.replaceWith('login');
      } else {
        // Let the route above this handle the error.
        return true;
      }
    }
  }
});

參考 - https://guides.emberjs.com/release/routing/loading-and-error-substates/

(要么)

當使用.then解決promise時,你可以直接處理它。

model(params) {
  return this.store.findAll('privileged-model').then((response) => {
    // handle success
  }, (response) => {
    // handle error
    if (response.status === '403') {
      // handle 403 errors
    }
  })
},

ember提供了內部錯誤處理程序。 因此,無論你的api發送什么錯誤都沒關系,ember將始終產生相同的錯誤信息。 “無效的適配器”。 如果您想顯示來自api響應的原始消息,您需要對您的響應進行串聯。 例如JSON.stringify(response.errors)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM