Skip to content

Commit

Permalink
fix: try/catch around fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
matmut7 committed Jan 8, 2024
1 parent 93c5dcb commit ff66e28
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/utils/rest-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import logger from "./logger"

const fetcher = async (url: string, params: Record<string, unknown>) => {
const response = await fetch(url, params)
if (!response.ok) {
logger.error({ response }, "Error status in response")
return null
try {
const response = await fetch(url, params)
if (!response.ok) {
logger.error({ response }, "Error status in response")
return null
}
return response
} catch (error) {
logger.error("Error attempting to fetch", error)
}
return response
}

export default fetcher

0 comments on commit ff66e28

Please sign in to comment.