mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
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:
1 parent
7f7d106c28
commit
5de419ee28
75 files changed
+1990
-1367
No files matched your search
+25
-117
@@ -1,182 +1,90 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { fetchWrapper, FetchError } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { GitStatusResponse, FileDiffResponse, GitCommit } from '@/types/git'
|
||||
|
||||
export class GitError extends Error {
|
||||
code?: string
|
||||
statusCode?: number
|
||||
|
||||
constructor(message: string, code?: string, statusCode?: number) {
|
||||
super(message)
|
||||
this.name = 'GitError'
|
||||
this.code = code
|
||||
this.statusCode = statusCode
|
||||
}
|
||||
}
|
||||
|
||||
interface ApiError {
|
||||
error: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
async function handleApiError(response: Response): Promise<never> {
|
||||
const data: ApiError = await response.json().catch(() => ({ error: 'An error occurred' }))
|
||||
throw new GitError(data.error, data.code, response.status)
|
||||
}
|
||||
|
||||
export async function fetchGitStatus(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/status`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/status`)
|
||||
}
|
||||
|
||||
export async function fetchReposGitStatus(repoIds: number[]): Promise<Map<number, GitStatusResponse>> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/git-status-batch`, {
|
||||
const data = await fetchWrapper<Record<string, GitStatusResponse>>(`${API_BASE_URL}/api/repos/git-status-batch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoIds })
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return new Map(Object.entries(data).map(([id, status]) => [Number(id), status as GitStatusResponse]))
|
||||
return new Map(Object.entries(data).map(([id, status]) => [Number(id), status]))
|
||||
}
|
||||
|
||||
export async function fetchFileDiff(repoId: number, path: string, includeStaged?: boolean): Promise<FileDiffResponse> {
|
||||
const params = new URLSearchParams({ path })
|
||||
if (includeStaged !== undefined) {
|
||||
params.set('includeStaged', String(includeStaged))
|
||||
}
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff-full?${params}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/diff-full`, {
|
||||
params: { path, includeStaged },
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchGitDiff(repoId: number, path: string): Promise<{ diff: string }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const data = await fetchWrapper<string>(`${API_BASE_URL}/api/repos/${repoId}/git/diff`, {
|
||||
params: { path },
|
||||
})
|
||||
return { diff: data }
|
||||
}
|
||||
|
||||
export async function fetchGitLog(repoId: number, limit?: number): Promise<{ commits: GitCommit[] }> {
|
||||
const params = limit ? `?limit=${limit}` : ''
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/log${params}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/log`, {
|
||||
params: { limit },
|
||||
})
|
||||
}
|
||||
|
||||
export async function gitFetch(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/fetch`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/fetch`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitPull(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/pull`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/pull`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitPush(repoId: number, setUpstream: boolean = false): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/push`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/push`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ setUpstream }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitCommit(repoId: number, message: string, stagedPaths?: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/commit`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/commit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message, stagedPaths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitStageFiles(repoId: number, paths: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/stage`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/stage`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ paths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitUnstageFiles(repoId: number, paths: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/unstage`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/unstage`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ paths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitReset(repoId: number, commitHash: string): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/reset`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/reset`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ commitHash }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export function useGitStatus(repoId: number | undefined) {
|
||||
@@ -227,7 +135,7 @@ function parseGitErrorMessage(message: string): string {
|
||||
}
|
||||
|
||||
export function getApiErrorMessage(error: unknown): string {
|
||||
if (error instanceof GitError) {
|
||||
if (error instanceof FetchError) {
|
||||
if (error.code === 'AUTH_FAILED') {
|
||||
return 'Git authentication failed. Check your credentials in Settings.'
|
||||
}
|
||||
@@ -237,6 +145,9 @@ export function getApiErrorMessage(error: unknown): string {
|
||||
if (error.code === 'NOT_FOUND') {
|
||||
return 'Repository or file not found.'
|
||||
}
|
||||
if (error.statusCode === 401) return 'Git authentication failed. Check your credentials in Settings.'
|
||||
if (error.statusCode === 409) return 'Merge conflict detected. Resolve conflicts before continuing.'
|
||||
if (error.statusCode === 404) return 'Repository or file not found.'
|
||||
return parseGitErrorMessage(error.message)
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
@@ -246,9 +157,6 @@ export function getApiErrorMessage(error: unknown): string {
|
||||
return parseGitErrorMessage(error)
|
||||
}
|
||||
const err = error as { status?: number; message?: string; error?: string }
|
||||
if (err?.status === 401) return 'Git authentication failed. Check your credentials in Settings.'
|
||||
if (err?.status === 409) return 'Merge conflict detected. Resolve conflicts before continuing.'
|
||||
if (err?.status === 404) return 'Repository or file not found.'
|
||||
const message = err?.message || err?.error || String(error) || 'An error occurred'
|
||||
return parseGitErrorMessage(message)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user