<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 錯誤處理 [TOC=2,3] 系統在處理用戶請求時,會遇到各種各樣的錯誤情況。如:系統內部錯誤,url 不存在,沒有權限,服務不可用等,這些情況下需要給用戶顯示對應的錯誤頁面。 ## 錯誤頁面 通過?`thinkjs`?命令創建項目時,會自動添加錯誤處理的邏輯文件以及相應的錯誤頁面。 錯誤邏輯文件路徑為?`src/common/controller/error.js`,該文件內容大致如下: ~~~ "use strict"; /** * error controller */ export default class extends think.controller.base { /** * display error page * @param {Number} status [] * @return {Promise} [] */ displayErrorPage(status){ let module = "common"; if(think.mode !== think.mode_module){ module = this.config("default_module"); } let file = `${module}/error/${status}.html`; let options = this.config("tpl"); options = think.extend({}, options, {type: "ejs"}); return this.display(file, options); } /** * Bad Request * @return {Promise} [] */ _400Action(){ return this.displayErrorPage(400); } /** * Forbidden * @return {Promise} [] */ _403Action(){ return this.displayErrorPage(403); } /** * Not Found * @return {Promise} [] */ _404Action(){ return this.displayErrorPage(404); } /** * Internal Server Error * @return {Promise} [] */ _500Action(){ return this.displayErrorPage(500); } /** * Service Unavailable * @return {Promise} [] */ _503Action(){ return this.displayErrorPage(503); } } ~~~ 對應的模版文件路徑為?`view/common/error_{Number}.html`。 ## 錯誤類型 系統默認支持的錯誤類型有?`400`,`403`,`404`,`500`?和?`503`。 #### 400 錯誤的請求,如:惡意構造一些非法的數據訪問、訪問的 url 不合法等。 #### 403 當前訪問沒有權限。 #### 404 訪問的 url 不存在。 #### 500 系統內部出現錯誤,導致當前請求不可用。 #### 503 服務不可用,需要等到恢復后才能訪問。 ## 擴展錯誤類型 項目里可以根據需要擴展錯誤類型,假如添加一個項目特有的錯誤?`600`,那么可以通過下面步驟進行: #### 1、添加 _600Action 在?`src/common/controller/error.js`?文件中,合適的位置添加如下的代碼: ~~~ _600Action(){ return this.displayErrorPage(600); } ~~~ #### 2、添加錯誤頁面 添加文件?`view/common/error_600.html`,并在文件里添加顯示的錯誤內容。 #### 3、顯示錯誤頁面 添加完錯誤后,需要在對應地方調用顯示錯誤才能讓用戶看到,可以通過?`think.statusAction`?方法實現。如: ~~~ export default class extends think.controller.base { indexAction(){ if(someError){ return think.statusAction(600, this.http); //顯示 600 錯誤,需要將 http 對象傳遞進去 } } } ~~~ ## 修改錯誤頁面樣式 修改錯誤頁面樣式,只需要修改對應的模版文件即可,如:修改?`404`?錯誤則修改模版文件`view/common/error_404.html`。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看