Skip to content

Commit

Permalink
Consolidate error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Sep 17, 2023
1 parent 1e287f4 commit a0a933c
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 85 deletions.
3 changes: 1 addition & 2 deletions pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ const Admin = () => {
}

if (isListingsError) {
// eslint-disable-next-line no-console
console.error('Error fetching listings')
console.error('[RW-Client] Error fetching listings')
}

if (!session) return null
Expand Down
7 changes: 5 additions & 2 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export const authOptions: NextAuthOptions = {
},
(error) => {
if (error) {
// eslint-disable-next-line no-console
console.error('SEND_VERIFICATION_EMAIL_ERROR', email, error)
console.error(
'[RW] SEND_VERIFICATION_EMAIL_ERROR',
email,
error,
)
return reject(
new Error(`SEND_VERIFICATION_EMAIL_ERROR ${error}`),
)
Expand Down
1 change: 1 addition & 0 deletions pages/api/auth/inviteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({
error: `Unable to invite user - ${e}`,
})
console.error(`[RW] Unable to invite user - ${e}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pages/api/categories/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
// eslint-disable-next-line sonarjs/no-small-switch
switch (req.method) {
case 'DELETE': {
console.log()
const { id: categoryId } = req.query
const category = await prisma.category.delete({
where: {
Expand All @@ -40,6 +39,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({
error: `Unable to update/delete category - ${e}`,
})
console.error(`[RW] Unable to update/delete category - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/categories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ const handler = async (
}
} catch (e) {
res.status(500)
res.json({
error: `Unable to ${req.method} process database operation - ${e}`,
})
res.json({ error: `Unable to ${req.method} category - ${e}` })
console.error(`[RW] Unable to ${req.method} category - ${e}`)
}
}

Expand Down
3 changes: 1 addition & 2 deletions pages/api/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
},
(error) => {
if (error) {
// eslint-disable-next-line no-console
console.error('Error sending feedback email', email, error)
console.error('[RW] Error sending feedback email', email, error)
}
},
)
Expand Down
5 changes: 2 additions & 3 deletions pages/api/listing/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({ listing })
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch listing by slug - ${e}`,
})
res.json({ error: `Unable to fetch listing by slug - ${e}` })
console.error(`[RW] Unable to fetch listing by slug - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/listings/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
} catch (e) {
res.status(500)
res.json({
error: `Unable to update/delete listing - ${e}`,
})
res.json({ error: `Unable to update/delete listing - ${e}` })
console.error(`[RW] Unable to update/delete listing - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/listings/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ const handler = async (
})
} catch (e) {
res.status(500)
res.json({
error: `Unable to save listing to database - ${e}`,
})
res.json({ error: `Unable to save listing to database - ${e}` })
console.error(`[RW] Unable to save listing to database - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/listings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({ listings })
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch listings from database - ${e}`,
})
res.json({ error: `Unable to fetch listings - ${e}` })
console.error(`[RW] Unable to fetch listings - ${e}`)
}
}

Expand Down
3 changes: 3 additions & 0 deletions pages/api/newsletter-subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ export default async (req, res) => {

return res.status(201).json({ error: null })
} catch (error) {
console.error(`[RW] Failed to sign up user to newsletter - ${error}`)
return res.status(400).json({
error:
'Oops, something went wrong. Please send an email to cambridgeresilienceweb@gmail.com and we can add you to the list.',
})
}
}



6 changes: 5 additions & 1 deletion pages/api/ownerships/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const handler = async (
}
} catch (e) {
res.status(500).send({
error: `Unable to fetch ownerships from database - ${e}`,
error: `Unable to fetch ownerships - ${e}`,
})
console.error(`[RW] Unable to fetch ownerships - ${e}`)
}
}

Expand All @@ -43,3 +44,6 @@ export const config = {

export default handler




46 changes: 7 additions & 39 deletions pages/api/ownerships/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
case 'GET':
res.json({ ownerships })
res.status(200)

break
// case 'PUT':
// const allOwnershipsToDisconnect = ownership.webs.map((l) => ({
// id: l.id,
// }))

// const updatedDataDisconnect: Prisma.OwnershipUpdateArgs = {
// where: {
// email: targetEmail,
// },
// data: {
// webs: {
// disconnect: allOwnershipsToDisconnect,
// },
// },
// }
// await prisma.ownership.update(updatedDataDisconnect)

// const websToConnect = webs.map((s) => ({ id: s.id }))
// const updatedDataConnect: Prisma.OwnershipUpdateArgs = {
// where: {
// email: targetEmail,
// },
// data: {
// webs: {
// connect: websToConnect,
// },
// },
// }
// const updatedOwnership = await prisma.ownership.update(
// updatedDataConnect,
// )

// res.status(200)
// res.json({ ownership: updatedOwnership })
// break
}
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch ownerships from database - ${e}`,
})
res.json({ error: `Unable to fetch ownerships - ${e}` })
console.error(`[RW] Unable to fetch ownerships - ${e}`)
}
}

Expand All @@ -108,3 +71,8 @@ export const config = {

export default handler






6 changes: 3 additions & 3 deletions pages/api/permissions/[webSlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({ permissions })
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch permissions from database - ${e}`,
})
res.json({ error: `Unable to fetch permissions - ${e}` })
console.error(`[RW] Unable to fetch permissions - ${e}`)
}
}

Expand All @@ -65,3 +64,4 @@ export const config = {

export default handler


5 changes: 2 additions & 3 deletions pages/api/permissions/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({ permissions })
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch permissions from database - ${e}`,
})
res.json({ error: `Unable to fetch permissions - ${e}` })
console.error(`[RW] Unable to fetch permissions - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/permissions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
} catch (e) {
res.status(500)
res.json({
error: `Unable to fetch permissions from database - ${e}`,
})
res.json({ error: `Unable to fetch permissions - ${e}` })
console.error(`[RW] Unable to fetch permissions - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ const handler = async (
}
} catch (e) {
res.status(500)
res.json({
error: `Unable to ${req.method} process database operation - ${e}`,
})
res.json({ error: `Unable to ${req.method} tags - ${e}` })
console.error(`[RW] Unable to ${req.method} tags - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/users/[email].ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.json({ user })
} catch (e) {
res.status(500)
res.json({
error: `Unable to get user from database - ${e}`,
})
res.json({ error: `Unable to fetch user - ${e}` })
console.error(`[RW] Unable to fetch user - ${e}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions pages/api/webs/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ const handler = async (
break
}
} catch (e) {
res.status(500).send({
error: `Unable to fetch web from database - ${e}`,
})
res.status(500).send({ error: `Unable to fetch web - ${e}` })
console.error(`[RW] Unable to fetch web - ${e}`)
}
}

Expand Down
7 changes: 2 additions & 5 deletions pages/api/webs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const handler = async (
? stringToBoolean(req.query.withListings as string)
: false

console.log('DINER', 'fetching webs from database')

try {
const webs: Data['webs'] = await prisma.location.findMany({
include: withListings
Expand All @@ -34,9 +32,8 @@ const handler = async (

res.status(200).json({ webs })
} catch (e) {
res.status(500).json({
error: `Unable to fetch webs from database - ${e}`,
})
res.status(500).json({ error: `Unable to fetch webs - ${e}` })
console.error(`[RW] Unable to fetch webs - ${e}`)
}
}

Expand Down

1 comment on commit a0a933c

@vercel
Copy link

@vercel vercel bot commented on a0a933c Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.