This commit is contained in:
Hongbo Wu
2023-07-26 18:07:25 +08:00
parent ced1a711eb
commit 61967fdde5
3 changed files with 7 additions and 10 deletions

View File

@ -4,12 +4,9 @@ import { Integration } from '../../entity/integration'
import { getRepository } from '../../entity/utils'
import { env } from '../../env'
import { wait } from '../../utils/helpers'
import { buildLogger } from '../../utils/logger'
import { getHighlightUrl } from '../highlights'
import { IntegrationService } from './integration'
const logger = buildLogger('app.dispatch')
interface ReadwiseHighlight {
// The highlight text, (technically the only field required in a highlight object)
text: string
@ -51,7 +48,7 @@ export class ReadwiseIntegration extends IntegrationService {
})
return response.status === 204 ? token : null
} catch (error) {
logger.error('error validating readwise token', error)
console.error('error validating readwise token', error)
return null
}
}
@ -69,7 +66,7 @@ export class ReadwiseIntegration extends IntegrationService {
// update integration syncedAt if successful
if (result) {
logger.info('updating integration syncedAt')
console.info('updating integration syncedAt')
await getRepository(Integration).update(integration.id, {
syncedAt: new Date(),
})
@ -132,14 +129,14 @@ export class ReadwiseIntegration extends IntegrationService {
error.response?.status === 429 &&
retryCount < 3
) {
logger.info('Readwise API rate limit exceeded, retrying...')
console.info('Readwise API rate limit exceeded, retrying...')
// wait for Retry-After seconds in the header if rate limited
// max retry count is 3
const retryAfter = error.response?.headers['retry-after'] || '10' // default to 10 seconds
await wait(parseInt(retryAfter, 10) * 1000)
return this.syncWithReadwise(token, highlights, retryCount + 1)
}
logger.error('Error creating highlights in Readwise', error)
console.error('Error creating highlights in Readwise', error)
return false
}
}

View File

@ -500,7 +500,7 @@ export const fetchFavicon = async (
const domain = new URL(realUrl).hostname
return `https://api.faviconkit.com/${domain}/128`
} catch (e) {
logger.info('Error fetching favicon', e)
console.log('Error fetching favicon', e)
return undefined
}
}

View File

@ -109,8 +109,8 @@ describe('saveNewsletterEmail', () => {
})
it('does not create a subscription if no unsubscribe header', async () => {
const url = 'https://blog.omnivore.app/no-unsubscribe'
nock('https://blog.omnivore.app').get('/no-unsubscribe').reply(404)
const url = 'https://omnivore.app/no_url?q=no-unsubscribe'
nock('https://omnivore.app').get('/no_url?q=no-unsubscribe').reply(404)
await saveNewsletterEmail(
{