- 40+ actions.ts 파일을 fetchWrapper 패턴으로 마이그레이션 - 토큰 리프레시 캐싱 로직 추가 (refresh-token.ts) - ApiErrorContext 추가로 전역 에러 처리 개선 - HR EmployeeForm 컴포넌트 개선 - 참조함(ReferenceBox) 기능 수정 - juil 테스트 URL 페이지 추가 - claudedocs 문서 업데이트 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
/**
|
|
* API 에러 타입 정의
|
|
*
|
|
* 전역 에러 핸들링을 위한 커스텀 에러 클래스들
|
|
*/
|
|
|
|
/**
|
|
* 인증 에러 (401 Unauthorized)
|
|
* - 토큰 만료
|
|
* - 세션 만료
|
|
* - 인증 실패
|
|
*/
|
|
export class AuthError extends Error {
|
|
public readonly status = 401;
|
|
public readonly code = 'AUTH_ERROR';
|
|
|
|
constructor(message: string = '인증이 만료되었습니다. 다시 로그인해주세요.') {
|
|
super(message);
|
|
this.name = 'AuthError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* API 에러 응답 타입
|
|
* Server Action에서 클라이언트로 전달되는 에러 형식
|
|
*/
|
|
export interface ApiErrorResponse {
|
|
__error: true;
|
|
__authError?: boolean;
|
|
status: number;
|
|
message: string;
|
|
code?: string;
|
|
}
|
|
|
|
/**
|
|
* 인증 에러 응답 생성 헬퍼
|
|
* Server Action에서 401 발생 시 반환할 객체
|
|
*/
|
|
export function createAuthErrorResponse(message?: string): ApiErrorResponse {
|
|
return {
|
|
__error: true,
|
|
__authError: true,
|
|
status: 401,
|
|
message: message || '인증이 만료되었습니다. 다시 로그인해주세요.',
|
|
code: 'AUTH_ERROR',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 일반 API 에러 응답 생성 헬퍼
|
|
*/
|
|
export function createErrorResponse(status: number, message: string, code?: string): ApiErrorResponse {
|
|
return {
|
|
__error: true,
|
|
__authError: status === 401,
|
|
status,
|
|
message,
|
|
code,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 응답이 에러인지 확인하는 타입 가드
|
|
*/
|
|
export function isApiError(response: unknown): response is ApiErrorResponse {
|
|
return (
|
|
typeof response === 'object' &&
|
|
response !== null &&
|
|
'__error' in response &&
|
|
(response as ApiErrorResponse).__error === true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 응답이 인증 에러인지 확인하는 타입 가드
|
|
*/
|
|
export function isAuthError(response: unknown): response is ApiErrorResponse {
|
|
return isApiError(response) && response.__authError === true;
|
|
} |