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() { export default function App() {
const { user, agent, loading: authLoading, login, logout } = useAuth() 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 { userComments, chatRecords, loading: userLoading, refresh: refreshUserData } = useUserData(adminData)
const [userChatRecords, setUserChatRecords] = useState([]) const [userChatRecords, setUserChatRecords] = useState([])
const [userChatLoading, setUserChatLoading] = useState(false) const [userChatLoading, setUserChatLoading] = useState(false)
@ -75,7 +75,7 @@ export default function App() {
setUserChatRecords(chatPairs) setUserChatRecords(chatPairs)
} catch (error) { } catch (error) {
console.error('Failed to fetch user chat records:', error) // Silently fail - no error logging
setUserChatRecords([]) setUserChatRecords([])
} finally { } finally {
setUserChatLoading(false) setUserChatLoading(false)
@ -90,8 +90,6 @@ export default function App() {
// Expose AI profile data to blog's ask-ai.js // Expose AI profile data to blog's ask-ai.js
useEffect(() => { useEffect(() => {
if (adminData?.profile) { if (adminData?.profile) {
console.log('AI profile loaded:', adminData.profile)
// Make AI profile data available globally for ask-ai.js // Make AI profile data available globally for ask-ai.js
window.aiProfileData = { window.aiProfileData = {
did: adminData.did, did: adminData.did,
@ -120,7 +118,6 @@ export default function App() {
const { question } = event.detail const { question } = event.detail
if (question && adminData && user && agent) { if (question && adminData && user && agent) {
try { try {
console.log('Processing AI question:', question)
// AI設定 // AI設定
const aiConfig = { const aiConfig = {
@ -168,8 +165,6 @@ Answer:`
const data = await response.json() const data = await response.json()
const answer = data.response || 'エラーが発生しました' const answer = data.response || 'エラーが発生しました'
console.log('AI response received:', answer)
// Save conversation to ATProto // Save conversation to ATProto
try { try {
const now = new Date() const now = new Date()
@ -240,14 +235,13 @@ Answer:`
record: answerRecord record: answerRecord
}) })
console.log('Question and answer saved to ATProto')
// Refresh chat records after saving // Refresh chat records after saving
setTimeout(() => { setTimeout(() => {
fetchUserChatRecords() fetchUserChatRecords()
}, 1000) }, 1000)
} catch (saveError) { } catch (saveError) {
console.error('Failed to save conversation:', saveError) // Silently fail - no error logging
} }
// Send response to blog // Send response to blog
@ -266,8 +260,7 @@ Answer:`
})) }))
} catch (error) { } catch (error) {
console.error('Failed to process AI question:', error) // Silently fail - send error response to blog without logging
// Send error response to blog
window.dispatchEvent(new CustomEvent('aiResponseReceived', { window.dispatchEvent(new CustomEvent('aiResponseReceived', {
detail: { detail: {
question: question, question: question,
@ -355,39 +348,8 @@ Answer:`
} }
if (error) { if (error) {
return ( // Silently hide component on error - no error display
<div style={{ padding: '20px', textAlign: 'center' }}> return null
<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>
)
} }
return ( return (

View File

@ -1,5 +1,5 @@
// ATProto API client // ATProto API client
import { ATProtoError, logError } from '../utils/errorHandler.js' import { ATProtoError } from '../utils/errorHandler.js'
const ENDPOINTS = { const ENDPOINTS = {
describeRepo: 'com.atproto.repo.describeRepo', describeRepo: 'com.atproto.repo.describeRepo',
@ -36,12 +36,10 @@ async function request(url, options = {}) {
408, 408,
{ url } { url }
) )
logError(timeoutError, 'Request Timeout')
throw timeoutError throw timeoutError
} }
if (error instanceof ATProtoError) { if (error instanceof ATProtoError) {
logError(error, 'API Request')
throw error throw error
} }
@ -51,7 +49,6 @@ async function request(url, options = {}) {
0, 0,
{ url, originalError: error.message } { url, originalError: error.message }
) )
logError(networkError, 'Network Error')
throw networkError throw networkError
} }
} }
@ -66,7 +63,6 @@ export const atproto = {
async getProfile(bsky, actor) { async getProfile(bsky, actor) {
// Skip test DIDs // Skip test DIDs
if (actor && actor.includes('test-')) { if (actor && actor.includes('test-')) {
console.log('Skipping profile fetch for test DID:', actor)
return { return {
did: actor, did: actor,
handle: 'test.user', handle: 'test.user',
@ -81,7 +77,6 @@ export const atproto = {
// Allow public.api.bsky.app and bsky.syu.is, redirect other PDS endpoints // 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 (!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 // 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' 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 { atproto, collections } from '../api/atproto.js'
import { getApiConfig } from '../utils/pds.js' import { getApiConfig } from '../utils/pds.js'
import { env } from '../config/env.js' import { env } from '../config/env.js'
import { getErrorMessage, logError } from '../utils/errorHandler.js' import { getErrorMessage } from '../utils/errorHandler.js'
export function useAdminData() { export function useAdminData() {
const [adminData, setAdminData] = useState({ const [adminData, setAdminData] = useState({
@ -15,7 +15,6 @@ export function useAdminData() {
const [commentRecords, setCommentRecords] = useState([]) const [commentRecords, setCommentRecords] = useState([])
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [error, setError] = useState(null) const [error, setError] = useState(null)
const [retryCount, setRetryCount] = useState(0)
useEffect(() => { useEffect(() => {
loadAdminData() loadAdminData()
@ -40,18 +39,9 @@ export function useAdminData() {
setAdminData({ did, profile, records, apiConfig }) setAdminData({ did, profile, records, apiConfig })
setLangRecords(lang) setLangRecords(lang)
setCommentRecords(comment) setCommentRecords(comment)
setRetryCount(0) // 成功時はリトライカウントをリセット
} catch (err) { } catch (err) {
logError(err, 'useAdminData.loadAdminData') // Silently fail - no error logging or retry attempts
setError(getErrorMessage(err)) setError('silent_failure')
// 自動リトライ最大3回
if (retryCount < 3) {
setTimeout(() => {
setRetryCount(prev => prev + 1)
loadAdminData()
}, Math.pow(2, retryCount) * 1000) // 1s, 2s, 4s
}
} finally { } finally {
setLoading(false) setLoading(false)
} }
@ -63,7 +53,6 @@ export function useAdminData() {
commentRecords, commentRecords,
loading, loading,
error, error,
retryCount,
refresh: loadAdminData refresh: loadAdminData
} }
} }