Skip to content

Commit

Permalink
suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman committed Dec 2, 2024
1 parent d7f4b19 commit 3961daa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/mappings/util/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ export async function fetchMetadata(url: string, job: Queue.Job) {

try {
const { status, data } = await api.get(finalUrl)
if (status < 400) {
if (status >= 200 && status < 300) {
if (data && typeof data === 'object' && !Array.isArray(data)) {
return data
}

job.log(`Invalid response from ${url}`)
job.log(data)
} else {
job.log(`Status code ${status} received from ${url}`)
}

throw new Error(`Failed to fetch metadata from ${url}`)
} catch (error: unknown) {
if (!Axios.isAxiosError(error)) {
Expand All @@ -58,8 +62,6 @@ export async function fetchMetadata(url: string, job: Queue.Job) {
job.log(`url: ${error.response.request.res.responseUrl} status: ${error.response.status.toString()}`)
job.log(`redirectsCount: ${error.response.request.res.redirects.length.toString()}`)
job.log(error.response.data)
} else {
job.log(`UnknownError: ${url} ${error.message}`)
}

throw error
Expand Down

0 comments on commit 3961daa

Please sign in to comment.