@xmpp/error
Advanced tools
Comparing version 0.11.0 to 0.12.0
38
index.js
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
"use strict"; | ||
@@ -7,30 +7,34 @@ // https://xmpp.org/rfcs/rfc6120.html#rfc.section.4.9.2 | ||
constructor(condition, text, application) { | ||
super(condition + (text ? ` - ${text}` : '')) | ||
this.name = 'XMPPError' | ||
this.condition = condition | ||
this.text = text | ||
this.application = application | ||
super(condition + (text ? ` - ${text}` : "")); | ||
this.name = "XMPPError"; | ||
this.condition = condition; | ||
this.text = text; | ||
this.application = application; | ||
} | ||
static fromElement(element) { | ||
const [condition, second, third] = element.children | ||
let text | ||
let application | ||
const [condition, second, third] = element.children; | ||
let text; | ||
let application; | ||
if (second) { | ||
if (second.is('text')) { | ||
text = second | ||
if (second.is("text")) { | ||
text = second; | ||
} else if (second) { | ||
application = second | ||
application = second; | ||
} | ||
if (third) application = third | ||
if (third) application = third; | ||
} | ||
const error = new this(condition.name, text ? text.text() : '', application) | ||
error.element = element | ||
return error | ||
const error = new this( | ||
condition.name, | ||
text ? text.text() : "", | ||
application, | ||
); | ||
error.element = element; | ||
return error; | ||
} | ||
} | ||
module.exports = XMPPError | ||
module.exports = XMPPError; |
@@ -7,3 +7,3 @@ { | ||
"bugs": "http://github.com/xmppjs/xmpp.js/issues", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"license": "ISC", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 10.0.0", | ||
"node": ">= 12.4.0", | ||
"yarn": ">= 1.0.0" | ||
@@ -22,3 +22,3 @@ }, | ||
}, | ||
"gitHead": "c0548a598826ae55cf195f296058b344064af7fd" | ||
"gitHead": "75f7bdf7805dced03f616b66dc16e2a067b46480" | ||
} |
@@ -12,9 +12,9 @@ # error | ||
```js | ||
const XMPPError = require('@xmpp/error') | ||
const XMPPError = require("@xmpp/error"); | ||
const error = new XMPPError('service-unavailable', 'optional text', element) | ||
error instanceof Error // true | ||
error.condition === 'service-unavailable' // true | ||
error.text === 'service-unavailabe - optional text' // true | ||
error.element === element // true | ||
const error = new XMPPError("service-unavailable", "optional text", element); | ||
error instanceof Error; // true | ||
error.condition === "service-unavailable"; // true | ||
error.text === "service-unavailabe - optional text"; // true | ||
error.element === element; // true | ||
``` |
2489
32