refactor(errors): classify auth and browser failures

This commit is contained in:
2026-07-03 13:20:16 +08:00
parent 8a71041b5d
commit 8a586e4471
7 changed files with 177 additions and 9 deletions
+12 -4
View File
@@ -1,6 +1,7 @@
"use client";
import { AuthApi, authApi } from "@/data/services/api";
import { ExceptionHandler } from "@/core/errors";
import { ApiError, AuthApi, authApi, ErrorCode } from "@/data/services/api";
import {
AppleLoginRequest,
FacebookLoginRequest,
@@ -141,9 +142,10 @@ export class AuthRepository implements IAuthRepository {
}
return response;
}).catch((e) => {
const errorResult = ExceptionHandler.handle(e);
log.error("[AuthRepository.guestLogin] API call FAILED", {
errorName: e?.name,
errorMessage: e?.message,
errorCode: errorResult.code,
errorMessage: errorResult.message,
});
return Result.err(e);
});
@@ -227,7 +229,13 @@ export class AuthRepository implements IAuthRepository {
async refreshToken(): Promise<Result<RefreshTokenResponse>> {
const existing = await this.storage.getRefreshToken();
if (!existing.success || !existing.data) {
return Result.err(new Error("No refresh token available"));
return Result.err(
new ApiError(
"HTTP_UNAUTHORIZED",
"No refresh token available",
ErrorCode.httpUnauthorized,
),
);
}
const refreshToken = existing.data;
return Result.wrap(async () => {