fix issues (#136)

* fix: prevent delete button click when card is not swiped open

* refactor: improve CreateRepoInput type safety

* security: require AUTH_SECRET and use secure random generation

* fix: SSH key path validation, async passphrase stripping, and port handling

* fix: use correct console methods for logger levels

* Add error handling to DB update functions and improve migration logging

* Add error handling for session lookup in auth middleware

* Add structured git error handling with user-friendly messages

- Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND,
  PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes
- Return structured error responses with summary and detail from backend
- Add GitErrorBanner component for better error display in UI
- Add optional onError callback to useGit hook for external error handling

* Make IPC server initialization/disposal async and fix SSH host key handler

* add try-catch error handling in frontend lib utilities

* remove unresolved promise handlers in speech synthesizer callbacks

* Extract error types to shared package

* Import GitErrorCode from shared package

* Refactor API layer to use shared FetchError and fetchWrapper

* Update prompt parser and source control components

* Extract MCP server list to separate component with improved badge menu UX

* merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility

* add separate loading state for passkey sign in

* refactor hooks: use fetchWrapper, improve error handling, add proper types

* replace browser confirm() with DeleteDialog component in settings

* fix: add missing variables parameter in React Query onError callbacks

* Refactor message parts to use separate Zustand store

* Update QuestionPrompt styling for light/dark mode
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-15 19:48:03 -05:00
1 parent 7f7d106c28
commit 5de419ee28
75 files changed
+1990 -1367

No files matched your search

+77 -85
View File
@@ -1,109 +1,101 @@
export class FetchError extends Error {
statusCode?: number
code?: string
import { FetchError } from '@opencode-manager/shared'
import type { ApiErrorResponse } from '@opencode-manager/shared'
constructor(message: string, statusCode?: number, code?: string) {
super(message)
this.name = 'FetchError'
this.statusCode = statusCode
this.code = code
}
}
interface ApiError {
error?: string
code?: string
message?: string
}
export { FetchError }
interface FetchWrapperOptions extends RequestInit {
timeout?: number
params?: Record<string, string | number | boolean | undefined | unknown>
params?: Record<string, string | number | boolean | undefined>
}
async function handleResponse(response: Response): Promise<never> {
const data: ApiError = await response.json().catch(() => ({ error: 'An error occurred' }))
throw new FetchError(data.error || data.message || 'Request failed', response.status, data.code)
const data: ApiErrorResponse = await response.json().catch(() => ({ error: 'An error occurred' }))
throw new FetchError(
data.error || 'Request failed',
response.status,
data.code,
data.detail
)
}
function buildUrl(url: string, params?: Record<string, string | number | boolean | undefined>): URL {
const urlObj = new URL(url, window.location.origin)
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
urlObj.searchParams.append(key, String(value))
}
})
}
return urlObj
}
async function fetchWithTimeout(
url: string,
options: FetchWrapperOptions = {}
): Promise<Response> {
const { timeout = 30000, params, ...fetchOptions } = options
const urlObj = buildUrl(url, params)
const controller = new AbortController()
const timeoutId = timeout > 0 ? setTimeout(() => controller.abort(), timeout) : null
try {
const response = await fetch(urlObj.toString(), {
...fetchOptions,
signal: controller.signal,
})
if (timeoutId) clearTimeout(timeoutId)
if (!response.ok) {
await handleResponse(response)
}
return response
} catch (error) {
if (timeoutId) clearTimeout(timeoutId)
if (error instanceof Error && error.name === 'AbortError') {
throw new FetchError('Request timeout', 408, 'TIMEOUT')
}
throw error
}
}
async function fetchWrapper<T = unknown>(
url: string,
options: FetchWrapperOptions = {}
): Promise<T> {
const { timeout = 30000, params, ...fetchOptions } = options
const urlObj = new URL(url, window.location.origin)
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
urlObj.searchParams.append(key, String(value))
}
})
}
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), timeout)
const response = await fetchWithTimeout(url, options)
try {
const response = await fetch(urlObj.toString(), {
...fetchOptions,
signal: controller.signal,
})
clearTimeout(timeoutId)
if (!response.ok) {
await handleResponse(response)
}
return response.json()
} catch (error) {
clearTimeout(timeoutId)
if (error instanceof Error && error.name === 'AbortError') {
throw new FetchError('Request timeout', 408, 'TIMEOUT')
}
throw error
return await response.json()
} catch {
throw new FetchError('Invalid JSON response', response.status, 'INVALID_JSON')
}
}
async function fetchWrapperText(
url: string,
options: FetchWrapperOptions = {}
): Promise<string> {
const response = await fetchWithTimeout(url, options)
return response.text()
}
async function fetchWrapperVoid(
url: string,
options: FetchWrapperOptions = {}
): Promise<void> {
await fetchWithTimeout(url, options)
}
async function fetchWrapperBlob(
url: string,
options: FetchWrapperOptions = {}
): Promise<Blob> {
const { timeout = 30000, params, ...fetchOptions } = options
const urlObj = new URL(url, window.location.origin)
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
urlObj.searchParams.append(key, String(value))
}
})
}
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), timeout)
try {
const response = await fetch(urlObj.toString(), {
...fetchOptions,
signal: controller.signal,
})
clearTimeout(timeoutId)
if (!response.ok) {
await handleResponse(response)
}
return response.blob()
} catch (error) {
clearTimeout(timeoutId)
if (error instanceof Error && error.name === 'AbortError') {
throw new FetchError('Request timeout', 408, 'TIMEOUT')
}
throw error
}
const response = await fetchWithTimeout(url, options)
return response.blob()
}
export { fetchWrapper, fetchWrapperBlob }
export { fetchWrapper, fetchWrapperText, fetchWrapperVoid, fetchWrapperBlob }