2
0
mirror of https://github.com/esiur/esiur-js.git synced 2026-04-03 21:48:21 +00:00
This commit is contained in:
2019-12-02 03:25:54 +03:00
parent 7d2bcc60f7
commit fb6276d6e5
15 changed files with 153 additions and 123 deletions

View File

@@ -36,7 +36,7 @@ export default class AsyncException extends Error
raise(type, code, message)
{
this.type = (type == 0 ? "Management" : "Execusion");
this.type = type;
this.code = code;
if (type == 0)
@@ -56,6 +56,6 @@ export default class AsyncException extends Error
toString()
{
return this.type + " (" + this.code + ") : " + this.message;
return (this.type == 0 ? "Management" : "Exception") + " (" + this.code + ") : " + this.message;
}
}

View File

@@ -30,13 +30,21 @@ import AsyncException from './AsyncException.js';
export default class AsyncReply extends Promise
{
then(callback)
then(callback, onError)
{
this.callbacks.push(callback);
if (this.ready)
callback(this.result, this);
if (callback != undefined)
{
this.callbacks.push(callback);
if (this.ready)
callback(this.result, this);
}
if (onError != undefined)
{
this.error(onError);
}
return this;
}
@@ -46,11 +54,6 @@ export default class AsyncReply extends Promise
this.then(callback);
}
// Alias for error()
catch(callback)
{
return this.error(callback);
}
error(callback)
{
@@ -103,7 +106,7 @@ export default class AsyncReply extends Promise
this.exception.raise(type, code, message);
if (this.errorCallbacks.length == 0)
throw this.exception;
throw this.exception;
else
for(var i = 0; i < this.errorCallbacks.length; i++)
this.errorCallbacks[i](this.exception, this);