Skip to content

Commit

Permalink
fix: try to fix some sentry error
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 3, 2024
1 parent fd81e9e commit 0b31c1e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/renderer/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const SentryConfig: BrowserOptions = {
/adsbygoogle/i.test(error.message) ||
/Failed to fetch/i.test(error.message) ||
error.message.includes("fetch failed") ||
error.message.includes("Unable to open cursor"))
error.message.includes("Unable to open cursor") ||
error.message.includes(
"Document is not focused.",
))
) {
return null
}
Expand All @@ -37,8 +40,9 @@ export const SentryConfig: BrowserOptions = {
return false
},
)
const isAbortError = error instanceof Error && error.name === "AbortError"

if (isPassthroughError) {
if (isPassthroughError || isAbortError) {
return null
}
return event
Expand Down
65 changes: 52 additions & 13 deletions src/renderer/src/hooks/biz/useEntryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
} from "@renderer/atoms/readability"
import { useIntegrationSettingKey } from "@renderer/atoms/settings/integration"
import { whoami } from "@renderer/atoms/user"
import { SimpleIconsEagle, SimpleIconsInstapaper, SimpleIconsReadwise } from "@renderer/components/ui/platform-icon/icons"
import {
SimpleIconsEagle,
SimpleIconsInstapaper,
SimpleIconsReadwise,
} from "@renderer/components/ui/platform-icon/icons"
import { COPY_MAP } from "@renderer/constants"
import { shortcuts } from "@renderer/constants/shortcuts"
import { tipcClient } from "@renderer/lib/client"
Expand Down Expand Up @@ -39,9 +43,15 @@ export const useEntryReadabilityToggle = ({
setReadabilityStatus({
[id]: ReadabilityStatus.WAITING,
})
const result = await tipcClient?.readability({
url,
})
const result = await tipcClient
?.readability({
url,
})
.catch(() => {
setReadabilityStatus({
[id]: ReadabilityStatus.FAILURE,
})
})

if (result) {
const status = getReadabilityStatus()[id]
Expand Down Expand Up @@ -162,7 +172,8 @@ export const useEntryActions = ({
icon: <SimpleIconsEagle />,
key: "saveToEagle",
hide:
!enableEagle || (checkEagle.isLoading ? true : !checkEagle.data) ||
!enableEagle ||
(checkEagle.isLoading ? true : !checkEagle.data) ||
!populatedEntry.entries.media?.length,
onClick: async () => {
if (
Expand Down Expand Up @@ -209,9 +220,18 @@ export const useEntryActions = ({
saved_using: "Follow",
},
})
toast.success(<>Saved to Readwise, <a target="_blank" className="underline" href={data.url}>view</a></>, {
duration: 3000,
})
toast.success(
<>
Saved to Readwise,
{" "}
<a target="_blank" className="underline" href={data.url}>
view
</a>
</>,
{
duration: 3000,
},
)
} catch {
toast.error("Failed to save to Readwise.", {
duration: 3000,
Expand All @@ -223,7 +243,11 @@ export const useEntryActions = ({
name: "Save to Instapaper",
icon: <SimpleIconsInstapaper />,
key: "saveToInstapaper",
hide: !enableInstapaper || !instapaperPassword || !instapaperUsername || !populatedEntry.entries.url,
hide:
!enableInstapaper ||
!instapaperPassword ||
!instapaperUsername ||
!populatedEntry.entries.url,
onClick: async () => {
try {
const data = await ofetch("https://www.instapaper.com/api/add", {
Expand All @@ -233,13 +257,28 @@ export const useEntryActions = ({
},
method: "POST",
headers: {
Authorization: `Basic ${btoa(`${instapaperUsername}:${instapaperPassword}`)}`,
Authorization: `Basic ${btoa(
`${instapaperUsername}:${instapaperPassword}`,
)}`,
},
parseResponse: JSON.parse,
})
toast.success(<>Saved to Instapaper, <a target="_blank" className="underline" href={`https://www.instapaper.com/read/${data.bookmark_id}`}>view</a></>, {
duration: 3000,
})
toast.success(
<>
Saved to Instapaper,
{" "}
<a
target="_blank"
className="underline"
href={`https://www.instapaper.com/read/${data.bookmark_id}`}
>
view
</a>
</>,
{
duration: 3000,
},
)
} catch {
toast.error("Failed to save to Instapaper.", {
duration: 3000,
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/hooks/common/factory/createHTMLMediaHook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @see https://github.com/streamich/react-use/blob/master/src/factory/createHTMLMediaHook.ts
*/
import { noop } from "foxact/noop"
import * as React from "react"
import { useEffect, useRef } from "react"
import { useEventCallback } from "usehooks-ts"
Expand Down Expand Up @@ -183,7 +184,7 @@ export default function createHTMLMediaHook<
}

if (!lockPlay) {
const promise = el.play()
const promise = el.play().catch(noop)
const isPromise = typeof promise === "object"

if (isPromise) {
Expand Down

0 comments on commit 0b31c1e

Please sign in to comment.