You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR
Embark happens have different approaches to how and when errors are being thrown and handled. Many APIs are callback based at the moment and expect the first parameter of a given callback to be the error. E.g.
^ This is a common pattern in NodeJS land and callback based APIs.
As of right now, Embark doesn't actually emit instances of Error in such cases, but rather just strings. E.g.
EmbarkJS.someAPI = (callback) => {
const err = 'this is an error message'
callback(err)
};
This is not too much of a big deal, as we don't actually throw anything anyways. However, it'd be better if all APIs that emit some sort of error, actually emit Error instances so one can react accordingly, especially when different error types can be thrown.
E.g.
EmbarkJS.someAPI((err, data) => {
if (err) {
switch (err.type) {
case EMBARK_ERR_CONN:
// ...
break;
...
}
}
})
This works the same way with promise-based APIs, with and without async/await:
EmbarkJS.someAPI = (callback) => {
return new Promise((resolve, reject) => {
const err = 'some error message';
reject(new Error(err))
});
}
// and then
try {
const someData = await EmbarkJS.someAPI()
} catch (e) {
switch (e.type) { // or instanceof or whatever we decide to do
...
}
}
We've discussed this here. This issue ensures we don't forget about it :)
The text was updated successfully, but these errors were encountered:
Overview
TL;DR
Embark happens have different approaches to how and when errors are being thrown and handled. Many APIs are callback based at the moment and expect the first parameter of a given callback to be the error. E.g.
^ This is a common pattern in NodeJS land and callback based APIs.
As of right now, Embark doesn't actually emit instances of
Error
in such cases, but rather just strings. E.g.This is not too much of a big deal, as we don't actually
throw
anything anyways. However, it'd be better if all APIs that emit some sort of error, actually emitError
instances so one can react accordingly, especially when different error types can be thrown.E.g.
This works the same way with promise-based APIs, with and without async/await:
We've discussed this here. This issue ensures we don't forget about it :)
The text was updated successfully, but these errors were encountered: