fix oauth network err

This commit is contained in:
2025-07-01 19:48:49 +09:00
parent d69c9aa09b
commit 4d01fb8507
3 changed files with 10 additions and 64 deletions

View File

@ -14,7 +14,7 @@ import OAuthCallback from './components/OAuthCallback.jsx'
export default function App() {
const { user, agent, loading: authLoading, login, logout } = useAuth()
const { adminData, langRecords, commentRecords, loading: dataLoading, error, retryCount, refresh: refreshAdminData } = useAdminData()
const { adminData, langRecords, commentRecords, loading: dataLoading, error, refresh: refreshAdminData } = useAdminData()
const { userComments, chatRecords, loading: userLoading, refresh: refreshUserData } = useUserData(adminData)
const [userChatRecords, setUserChatRecords] = useState([])
const [userChatLoading, setUserChatLoading] = useState(false)
@ -75,7 +75,7 @@ export default function App() {
setUserChatRecords(chatPairs)
} catch (error) {
console.error('Failed to fetch user chat records:', error)
// Silently fail - no error logging
setUserChatRecords([])
} finally {
setUserChatLoading(false)
@ -90,8 +90,6 @@ export default function App() {
// Expose AI profile data to blog's ask-ai.js
useEffect(() => {
if (adminData?.profile) {
console.log('AI profile loaded:', adminData.profile)
// Make AI profile data available globally for ask-ai.js
window.aiProfileData = {
did: adminData.did,
@ -120,7 +118,6 @@ export default function App() {
const { question } = event.detail
if (question && adminData && user && agent) {
try {
console.log('Processing AI question:', question)
// AI設定
const aiConfig = {
@ -168,8 +165,6 @@ Answer:`
const data = await response.json()
const answer = data.response || 'エラーが発生しました'
console.log('AI response received:', answer)
// Save conversation to ATProto
try {
const now = new Date()
@ -240,14 +235,13 @@ Answer:`
record: answerRecord
})
console.log('Question and answer saved to ATProto')
// Refresh chat records after saving
setTimeout(() => {
fetchUserChatRecords()
}, 1000)
} catch (saveError) {
console.error('Failed to save conversation:', saveError)
// Silently fail - no error logging
}
// Send response to blog
@ -266,8 +260,7 @@ Answer:`
}))
} catch (error) {
console.error('Failed to process AI question:', error)
// Send error response to blog
// Silently fail - send error response to blog without logging
window.dispatchEvent(new CustomEvent('aiResponseReceived', {
detail: {
question: question,
@ -355,39 +348,8 @@ Answer:`
}
if (error) {
return (
<div style={{ padding: '20px', textAlign: 'center' }}>
<h1>エラー</h1>
<div style={{
background: '#fee',
color: '#c33',
padding: '15px',
borderRadius: '5px',
margin: '20px auto',
maxWidth: '500px',
border: '1px solid #fcc'
}}>
<p><strong>エラー:</strong> {error}</p>
{retryCount > 0 && (
<p><small>自動リトライ中... ({retryCount}/3)</small></p>
)}
</div>
<button
onClick={refreshAdminData}
style={{
background: '#007bff',
color: 'white',
border: 'none',
padding: '10px 20px',
borderRadius: '5px',
cursor: 'pointer',
fontSize: '16px'
}}
>
再読み込み
</button>
</div>
)
// Silently hide component on error - no error display
return null
}
return (

View File

@ -1,5 +1,5 @@
// ATProto API client
import { ATProtoError, logError } from '../utils/errorHandler.js'
import { ATProtoError } from '../utils/errorHandler.js'
const ENDPOINTS = {
describeRepo: 'com.atproto.repo.describeRepo',
@ -36,12 +36,10 @@ async function request(url, options = {}) {
408,
{ url }
)
logError(timeoutError, 'Request Timeout')
throw timeoutError
}
if (error instanceof ATProtoError) {
logError(error, 'API Request')
throw error
}
@ -51,7 +49,6 @@ async function request(url, options = {}) {
0,
{ url, originalError: error.message }
)
logError(networkError, 'Network Error')
throw networkError
}
}
@ -66,7 +63,6 @@ export const atproto = {
async getProfile(bsky, actor) {
// Skip test DIDs
if (actor && actor.includes('test-')) {
console.log('Skipping profile fetch for test DID:', actor)
return {
did: actor,
handle: 'test.user',
@ -81,7 +77,6 @@ export const atproto = {
// Allow public.api.bsky.app and bsky.syu.is, redirect other PDS endpoints
if (!bsky.includes('public.api.bsky.app') && !bsky.includes('bsky.syu.is')) {
// If it's a PDS endpoint that doesn't support getProfile, redirect to public API
console.warn(`getProfile called with PDS endpoint ${bsky}, redirecting to public API`)
apiEndpoint = 'https://public.api.bsky.app'
}

View File

@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'
import { atproto, collections } from '../api/atproto.js'
import { getApiConfig } from '../utils/pds.js'
import { env } from '../config/env.js'
import { getErrorMessage, logError } from '../utils/errorHandler.js'
import { getErrorMessage } from '../utils/errorHandler.js'
export function useAdminData() {
const [adminData, setAdminData] = useState({
@ -15,7 +15,6 @@ export function useAdminData() {
const [commentRecords, setCommentRecords] = useState([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
const [retryCount, setRetryCount] = useState(0)
useEffect(() => {
loadAdminData()
@ -40,18 +39,9 @@ export function useAdminData() {
setAdminData({ did, profile, records, apiConfig })
setLangRecords(lang)
setCommentRecords(comment)
setRetryCount(0) // 成功時はリトライカウントをリセット
} catch (err) {
logError(err, 'useAdminData.loadAdminData')
setError(getErrorMessage(err))
// 自動リトライ最大3回
if (retryCount < 3) {
setTimeout(() => {
setRetryCount(prev => prev + 1)
loadAdminData()
}, Math.pow(2, retryCount) * 1000) // 1s, 2s, 4s
}
// Silently fail - no error logging or retry attempts
setError('silent_failure')
} finally {
setLoading(false)
}
@ -63,7 +53,6 @@ export function useAdminData() {
commentRecords,
loading,
error,
retryCount,
refresh: loadAdminData
}
}