Skip to content

Commit

Permalink
fix(route): 🐛 reply with proper return codes on errors or exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
djdembeck committed Mar 29, 2022
1 parent e6faedc commit e34e182
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config/routes/authors/search/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ async function routes (fastify, options) {
const name = request.query.name

if (!name) {
reply.code(400)
throw new Error('No search params provided')
}

Expand Down
1 change: 1 addition & 0 deletions src/config/routes/authors/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function routes (fastify, options) {
// First, check ASIN validity
const commonHelpers = new SharedHelper()
if (!commonHelpers.checkAsinValidity(request.params.asin)) {
reply.code(400)
throw new Error('Bad ASIN')
}

Expand Down
2 changes: 2 additions & 0 deletions src/config/routes/books/chapters/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function routes (fastify, options) {
// First, check ASIN validity
const commonHelpers = new SharedHelper()
if (!commonHelpers.checkAsinValidity(request.params.asin)) {
reply.code(400)
throw new Error('Bad ASIN')
}

Expand Down Expand Up @@ -45,6 +46,7 @@ async function routes (fastify, options) {
}
return newDbItem
} else {
reply.code(404)
throw new Error('No Chapters')
}
}
Expand Down
1 change: 1 addition & 0 deletions src/config/routes/books/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async function routes (fastify, options) {
// First, check ASIN validity
const commonHelpers = new SharedHelper()
if (!commonHelpers.checkAsinValidity(request.params.asin)) {
reply.code(400)
throw new Error('Bad ASIN')
}

Expand Down
1 change: 1 addition & 0 deletions src/config/routes/books/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function routes (fastify, options) {
// First, check ASIN validity
const commonHelpers = new SharedHelper()
if (!commonHelpers.checkAsinValidity(request.params.asin)) {
reply.code(400)
throw new Error('Bad ASIN')
}

Expand Down

0 comments on commit e34e182

Please sign in to comment.