refactor(main): ipcSuccess/ipcError 헬퍼 통일 + catch(error) 패턴 (WS-PATTERN)
- cloud-sync-handlers 수동 ok/fail -> ipcSuccess/ipcError 헬퍼 (6 핸들러)
- catch {} -> catch(error) 에러 메시지 보강 32건 (11 ipc handler 파일)
KEEP: template-handlers(주석 명시 에러 무시), license-handlers(이미 헬퍼 사용),
audio-handlers stop().catch(() => {})(의도적 무시)
정책: docs/REFACTOR_POLICY.md DP2
This commit is contained in:
parent
4c256202f7
commit
5b6e7aae6b
11 changed files with 133 additions and 93 deletions
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
import { ipcMain, BrowserWindow } from 'electron'
|
||||
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
import type { IPCResult } from '@d3ro/core/errors'
|
||||
import { ipcSuccess, ipcError, ErrorCode, D3ROError } from '@d3ro/core/errors'
|
||||
import { getCloudSyncService } from '../services/CloudSyncService'
|
||||
import { getLogger } from '../services/LoggerService'
|
||||
import { configSet } from '../services/ConfigService'
|
||||
|
|
@ -15,56 +14,57 @@ interface SignInParams {
|
|||
provider: 'google' | 'github'
|
||||
}
|
||||
|
||||
function ok<T>(data: T): IPCResult<T> {
|
||||
return { success: true, data }
|
||||
}
|
||||
|
||||
function fail(error: unknown): IPCResult<never> {
|
||||
if (error instanceof D3ROError) {
|
||||
return { success: false, error: { code: error.code, message: error.message } }
|
||||
}
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
return {
|
||||
success: false,
|
||||
error: { code: ErrorCode.LLMProcessingFailed, message }
|
||||
}
|
||||
}
|
||||
|
||||
export function registerCloudSyncHandlers(): void {
|
||||
const sync = getCloudSyncService()
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.GET_STATE, () => {
|
||||
try {
|
||||
return ok(sync.getState())
|
||||
return ipcSuccess(sync.getState())
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.SIGN_IN, async (_e, params: SignInParams) => {
|
||||
try {
|
||||
await sync.startSignIn(params.provider)
|
||||
return ok({ started: true })
|
||||
return ipcSuccess({ started: true })
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.HANDLE_CALLBACK, async (_e, params: { code: string }) => {
|
||||
try {
|
||||
await sync.handleAuthCallback(params.code)
|
||||
return ok(sync.getState())
|
||||
return ipcSuccess(sync.getState())
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.SIGN_OUT, async () => {
|
||||
try {
|
||||
await sync.signOut()
|
||||
return ok(sync.getState())
|
||||
return ipcSuccess(sync.getState())
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -72,9 +72,13 @@ export function registerCloudSyncHandlers(): void {
|
|||
try {
|
||||
const result = await sync.pushAll()
|
||||
configSet('cloudSyncLastAt', Date.now())
|
||||
return ok(result)
|
||||
return ipcSuccess(result)
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -82,9 +86,13 @@ export function registerCloudSyncHandlers(): void {
|
|||
try {
|
||||
const result = await sync.pullAll()
|
||||
configSet('cloudSyncLastAt', Date.now())
|
||||
return ok(result)
|
||||
return ipcSuccess(result)
|
||||
} catch (e) {
|
||||
return fail(e)
|
||||
if (e instanceof D3ROError) {
|
||||
return ipcError(e.code, e.message)
|
||||
}
|
||||
const message = e instanceof Error ? e.message : String(e)
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, message)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue