Adjust how error message is caught and displayed
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export default class Exception {
|
||||
export default class Exception extends Error {
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
@@ -24,17 +24,8 @@ export default class Exception {
|
||||
*
|
||||
*/
|
||||
constructor(message, temporary) {
|
||||
this.message = message;
|
||||
super(message);
|
||||
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error string
|
||||
*
|
||||
* @returns {string} Error message
|
||||
*
|
||||
*/
|
||||
toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,12 +222,23 @@ export class Multiple {
|
||||
*
|
||||
*/
|
||||
close() {
|
||||
return this.closeWithReason("Reader is closed");
|
||||
}
|
||||
|
||||
/**
|
||||
* close current reading
|
||||
*
|
||||
* @param {string} reason Reason
|
||||
*
|
||||
*/
|
||||
closeWithReason(reason) {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.closed = true;
|
||||
this.subscribe.reject(new Exception("Reader is closed", false));
|
||||
this.subscribe.reject(new Exception(reason, false));
|
||||
this.subscribe.disable(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,17 +328,23 @@ export class Reader {
|
||||
*
|
||||
*/
|
||||
close() {
|
||||
return this.closeWithReason("Reader is closed");
|
||||
}
|
||||
|
||||
/**
|
||||
* close current reading
|
||||
*
|
||||
* @param {string} reason Reason
|
||||
*
|
||||
*/
|
||||
closeWithReason(reason) {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.closed = true;
|
||||
this.buffers.reject(
|
||||
new Exception(
|
||||
"Reader is closed, and thus " + "cannot be operated on",
|
||||
false
|
||||
)
|
||||
);
|
||||
this.buffers.reject(new Exception(reason, false));
|
||||
this.buffers.disable(reason);
|
||||
|
||||
return this.multiple.close();
|
||||
}
|
||||
|
||||
@@ -66,11 +66,7 @@ export class Sender {
|
||||
|
||||
this.subscribe.reject(new Exception("Sender has been closed", false));
|
||||
|
||||
try {
|
||||
await this.sendingPoc;
|
||||
} catch (e) {
|
||||
// Do nothing
|
||||
}
|
||||
this.sendingPoc.catch(() => {});
|
||||
|
||||
this.reject(new Exception("Sending has been cancelled", true));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export class Subscribe {
|
||||
this.res = null;
|
||||
this.rej = null;
|
||||
this.pending = [];
|
||||
this.disabled = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +79,10 @@ export class Subscribe {
|
||||
*
|
||||
*/
|
||||
subscribe() {
|
||||
if (this.disabled) {
|
||||
throw new Exception(this.disabled, false);
|
||||
}
|
||||
|
||||
if (this.pending.length > 0) {
|
||||
let p = this.pending.shift();
|
||||
|
||||
@@ -111,4 +116,14 @@ export class Subscribe {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable current subscriber when all internal data is readed
|
||||
*
|
||||
* @param {string} reason Reason of the disable
|
||||
*
|
||||
*/
|
||||
disable(reason) {
|
||||
this.disabled = reason;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user