Better handling of user personalization errors

This commit is contained in:
Jackson Harper
2024-05-08 16:09:02 +08:00
parent dad7cfdc41
commit 976f5e5a6b
4 changed files with 21 additions and 29 deletions

View File

@ -9,9 +9,10 @@ export const scheduleDigest = async (
request: DigestRequest
): Promise<boolean> => {
try {
const result = await apiPoster(`/api/digest/v1/`, request)
console.log('RESULT: ', result)
return true
const response = await apiPoster(`/api/digest/v1/`, request)
return (
response.status == 202 || response.status == 201 || response.status == 200
)
} catch (error) {
console.log('error scheduling job: ', error)
return false

View File

@ -68,19 +68,14 @@ export function apiFetcher(path: string): Promise<unknown> {
})
}
export function apiPoster(path: string, body: any): Promise<unknown> {
export function apiPoster(path: string, body: any): Promise<Response> {
const url = new URL(path, fetchEndpoint)
return fetch(url.toString(), {
method: 'POST',
credentials: 'include',
mode: 'cors',
// headers: {
// Accept: 'application/json',
// 'X-OmnivoreClient': 'web',
// },
headers: requestHeaders(),
body: JSON.stringify(body),
}).then((result) => {
return result.json()
})
}

View File

@ -70,12 +70,6 @@ export function useGetUserPersonalization(): UserPersonalizationResult {
const { data, error, mutate } = useSWR(query, publicGqlFetcher)
const response = data as Response | undefined
console.log(
'useGetUserPersonalization:data: ',
response?.getUserPersonalization?.userPersonalization,
'data',
data
)
if (
!response ||

View File

@ -569,19 +569,21 @@ const DigestSection = (): JSX.Element => {
showErrorToast('Error updating digest config')
}
if (updatedChannels.length) {
// Queue the daily job
console.log('queueing daily digest job')
const scheduled = await scheduleDigest({
schedule: 'daily',
voices: ['openai-nova'],
})
if (scheduled) {
showSuccessToast(
'Your daily digest is scheduled to start tomorrow.'
)
} else {
showErrorToast('Error scheduling your daily digest')
}
// Schedule the job in a timeout so the user notifications
// make sense
setTimeout(async () => {
const scheduled = await scheduleDigest({
schedule: 'daily',
voices: ['openai-nova'],
})
if (scheduled) {
showSuccessToast(
'Your daily digest is scheduled to start tomorrow.'
)
} else {
showErrorToast('Error scheduling your daily digest')
}
}, 500)
} else {
console.log('deleting daily digest job')
}