如何处理类星体启动文件中的错误
在我们的类星体应用程序中,我们有一些引导文件,其中一些可以遇到一个异常,该例外应该阻止该应用程序正常启动,而应显示错误。
这种情况有一些最佳实践吗?我在文档中没有发现太多。
我的方法是以下方法,如果错误发生/重定向到错误页面并显示错误。
我需要以某种方式将错误传递给错误页面:
- 将消息传递给get参数将是一个坏主意= > XS
- i也无法传递错误ID/键,因为错误可能来自带有各种消息的服务器,
- 该消息存储在Vuex Store中,因为在调用
refform()
之后,该商店已重置。
因此,我认为也许有更好的方法可以在引导文件中处理错误? 停止当前启动和goto错误页面...
这是一个简化的示例,它将以/error 页面结束,但使用store.error
empty,拒绝()
将重新启动应用程序重置Store
。
export default ({ app, store, urlPath }) => {
// required to prevent invinite loop, the reject(url) will reboot application
if (urlPath.indexOf("error") !== -1) {
// TODO be more specific then indexOf("error")
return;
}
return new Promise((resolve, reject) => {
doSomeServerCommunication()
.then((result) => {
resolve();
})
.catch((e) => {
store.commit("appStore/updateError", e);
reject({ url: window.location.origin + "/app/error" });
return;
});
});
};
In our quasar application we have a few boot files, some of them can run into an exception which should block the application from starting normally, instead an error should be displayed.
Is there some best-practice for such a case? I didn't find much in the documentation.
My approach was the following, if an error occurs forward/redirect to an error page and display the error.
I need to somehow pass the error to the error-page:
- passing the message as GET parameter would be a bad idea => XSS
- I also cannot pass an error ID/Key because the error may come from a server with various messages
- Storing the error in a vuex store does not work because the store is reset after
reject()
is called.
So I was thinking maybe there is a better way of doing handling errors in boot files?
Stop current booting and goto error-page...
Here is an reduced example which will end in the /error page but with the store.error
empty, reject()
will reboot the application reset the store
.
export default ({ app, store, urlPath }) => {
// required to prevent invinite loop, the reject(url) will reboot application
if (urlPath.indexOf("error") !== -1) {
// TODO be more specific then indexOf("error")
return;
}
return new Promise((resolve, reject) => {
doSomeServerCommunication()
.then((result) => {
resolve();
})
.catch((e) => {
store.commit("appStore/updateError", e);
reject({ url: window.location.origin + "/app/error" });
return;
});
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论