浏览代码

Handle null being passed to parseErrorStanza

JC Brand 3 月之前
父节点
当前提交
7d8ea3b9d6
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      src/headless/shared/parsers.js

+ 2 - 1
src/headless/shared/parsers.js

@@ -17,13 +17,14 @@ import * as errors from './errors.js';
 const { NS } = Strophe;
 const { NS } = Strophe;
 
 
 /**
 /**
- * @param {Element|Error} stanza - The stanza to be parsed. As a convenience,
+ * @param {Element|Error|null} stanza - The stanza to be parsed. As a convenience,
  * an Error element can be passed in as well, so that this function can be
  * an Error element can be passed in as well, so that this function can be
  * called in a catch block without first checking if a stanza or Error
  * called in a catch block without first checking if a stanza or Error
  * element was received.
  * element was received.
  * @returns {Promise<Error|errors.StanzaError|null>}
  * @returns {Promise<Error|errors.StanzaError|null>}
  */
  */
 export async function parseErrorStanza(stanza) {
 export async function parseErrorStanza(stanza) {
+    if (stanza === null) return null;
     if (stanza instanceof Error) return stanza;
     if (stanza instanceof Error) return stanza;
     if (stanza.getAttribute('type') !== 'error') return null;
     if (stanza.getAttribute('type') !== 'error') return null;