## 概要 [Task1495: 画面実装(ユーザー認証画面)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1495) - メールの認証URLから、認証を実行して結果を表示するまでの画面を実装しました。 - 認証画面 - 認証完了画面 - 成功 - 失敗 - 認証済み - エラーハンドリング用のメソッドを`common`に追加しました。 - メールに送信される認証URLのパスを認証画面のパスに修正しました。 ## レビューポイント - エラーハンドリング用の処理は適切でしょうか? - 改行を画面に対応させるために暫定の処置を入れています。対応に問題はないでしょうか。 - アカウント登録のメール送信について、パスを対象となる画面のパス`mail-confirm/`に変更しました。 - 対応として適切でしょうか? ## UIの変更 - [Task1495](https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task1495?csf=1&web=1&e=bqT7nz) ## 動作確認状況 - ローカルで確認
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
import { AxiosError } from "axios";
|
|
import { isError } from "lodash";
|
|
import { ErrorResponse } from "../../api";
|
|
import { errorCodes } from "./code";
|
|
import { ErrorCodeType, ErrorObject } from "./types";
|
|
|
|
export const createErrorObject = (error: unknown): ErrorObject => {
|
|
// 最低限通常のエラーかを判定
|
|
// Error以外のものがthrowされた場合
|
|
// 基本的にないはずだがプログラム上あるので拾う
|
|
if (!isError(error)) {
|
|
return {
|
|
message: "not error type.",
|
|
code: "E009999",
|
|
};
|
|
}
|
|
|
|
// Axiosエラー 通信してのエラーであるかを判定
|
|
if (!isAxiosError(error)) {
|
|
return {
|
|
message: "not axios error.",
|
|
code: "E009999",
|
|
};
|
|
}
|
|
|
|
const errorResponse = error.response;
|
|
if (!errorResponse) {
|
|
return {
|
|
message: error.message,
|
|
code: "E009999",
|
|
statusCode: errorResponse,
|
|
};
|
|
}
|
|
|
|
const { data } = errorResponse;
|
|
|
|
// 想定しているエラーレスポンスの型か判定
|
|
if (!isErrorResponse(data)) {
|
|
return {
|
|
message: error.message,
|
|
code: "E009999",
|
|
statusCode: errorResponse.status,
|
|
};
|
|
}
|
|
|
|
const { message, code } = data;
|
|
|
|
// 想定しているエラーコードかを判定
|
|
if (!isErrorCode(code)) {
|
|
return {
|
|
message,
|
|
code: "E009999",
|
|
statusCode: errorResponse.status,
|
|
};
|
|
}
|
|
|
|
return {
|
|
message,
|
|
code,
|
|
statusCode: errorResponse.status,
|
|
};
|
|
};
|
|
|
|
const isAxiosError = (e: unknown): e is AxiosError => {
|
|
const error = e as AxiosError;
|
|
return error?.isAxiosError ?? false;
|
|
};
|
|
|
|
const isErrorResponse = (error: unknown): error is ErrorResponse => {
|
|
const errorResponse = error as ErrorResponse;
|
|
if (
|
|
errorResponse === undefined ||
|
|
errorResponse.message === undefined ||
|
|
errorResponse.code === undefined
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
const isErrorCode = (errorCode: string): errorCode is ErrorCodeType =>
|
|
errorCodes.includes(errorCode as ErrorCodeType);
|