-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ガイドのVue.js編にエラーハンドラーの設定方法を追加する #1362
Comments
リリース、サブissue進捗・ Dresscaのカスタムエラーハンドラーの実装の修正 ・ドキュメントの追加、 カスタムエラーハンドラーについて見直すべき点が多数出てきたため、 |
コンポーネント以外ではプラグインをinjectできない問題サービスクラスなど、 しかし、この場合、カスタムエラーハンドラーを使用する際に、 よって、カスタムエラーハンドラーは必ずVueのコンポーネントから呼ぶというように定めたほうがよい可能性がある。 そうなると、 そのため、このような構成が妥当なのかどうかを検討すべき。 処理フロー図とは合致している。
業務例外をハンドリングしてユーザーに通知するのはプレゼンテーションロジックのはずなので、
エラー
authentication-service.tsの実装例export const authenticationService = {
async signInAzureADB2C() {
const authenticationStore = useAuthenticationStore();
const customErrorHandler = useCustomErrorHandler();
try {
const response = await msalInstance.loginPopup(loginRequest);
msalInstance.setActiveAccount(response.account);
authenticationStore.updateAuthenticated(true);
return true;
} catch (error) {
customErrorHandler.handle(error, () => {
authenticationStore.updateAuthenticated(false);
});
return false;
}
}, |
Serviceクラスから直でimportした場合、 エラー
エラーになるコード import { createCustomErrorHandler } from '@/shared/error-handler/custom-error-handler';
export async function updateItemInBasket(
catalogItemId: number,
newQuantity: number,
) {
const basketStore = useBasketStore();
const customErrorHandler = createCustomErrorHandler();
// 直前に追加された商品の表示を更新するためIDを削除
basketStore.deleteAddedItemId();
try {
await basketStore.update(catalogItemId, newQuantity);
} catch (error) {
customErrorHandler.handle(error, () => alert(error));
} finally {
await basketStore.fetch();
}
} |
dependency-cruiserでチェックすると、 InjectionKeyがインターフェースになって、
|
|
要検証・検討ポイント暫定案main.tsに既定のカスタムエラーハンドラーを実装してしまうmain.tsにカスタムエラーハンドラーの実装を書いてしまい、 routerを使用する同じmain.ts中に入れてしまえば、routerをimportすると警告が出る問題は解決するはず。 showToastを使用するshowToastに関してはapp.useしていないのでそのままだとうまく動かないかもしれない。 カスタムエラーハンドラーからvueアプリケーションへの依存を取り除くカスタムエラーハンドラーがVueアプリケーションの機能(vue-routerやToastコンポーネント)に依存していることが問題。レイヤーの関係が逆転しているという理解。 イメージとしては、
import { showToast } from '@/services/notification/notificationService';
import { useRoutingStore } from '@/stores/routing/routing';
import { router } from '@/router';
if (error instanceof UnauthorizedError) {
// ログ出力
// ユーザーへの通知
// イベントを発生させてQueueに詰める
}
|
・カスタムイベントを格納するキュー構造のストアを作成する Vuexでキューを実装する TypeScriptでCustomEventを起動して受信したいとき |
概要
「プロジェクトの共通設定」と「開発に使用するパッケージ」の間に、

「エラーハンドラーの設定」ページを追加し、
システム例外を補足するグローバルエラーハンドラーと、
業務例外を補足するカスタムエラーハンドラーについて実装、設定方法を記載する。
詳細 / 機能詳細(オプション)
ガイドには、どのプロジェクトでも実施すべき初期構築作業を記載したい。
たとえばMarisのバックエンド側では、
下記のようにエラーハンドラーの実装・設定方法を記載している。
完了条件
The text was updated successfully, but these errors were encountered: