Skip to content

Commit

Permalink
refactor: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 29, 2023
1 parent a287558 commit 8319742
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions trifid/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,26 @@ function factory () {
}
}
if (shapePath) {
return fetch(`https://raw.githubusercontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
.then(rawGithub => {
if (rawGithub.ok) {
res.set('Content-Type', 'text/turtle')
} else {
res.status(500)
}
Readable.fromWeb(rawGithub.body).pipe(res)
})
.catch((e) => {
res.status(502)
res.send(`Error fetching shape: ${e.message}`)
})
try {
const rawGithub = await fetch(`https://raw.githubusercontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
if (rawGithub.ok) {
res.set('Content-Type', 'text/turtle')
} else {
res.status(500)
}
// if the shape does not exist, we return a 404
if (rawGithub.status === 404) {
return res.sendStatus(404)
}
/** @type {any | null} */
const body = rawGithub.body
if (!rawGithub.body) {
throw new Error('No body')
}
return Readable.fromWeb(body).pipe(res)
} catch (e) {
return res.status(502).send(`Error fetching shape: ${e.message}`)
}
}
}

Expand Down

0 comments on commit 8319742

Please sign in to comment.