Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antti | Error structure changes #17

Merged
merged 20 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b62d95c
Updated packages
anttiasmala Mar 3, 2024
db6e3e6
Created a new folder backend. Created a file called handleError.ts
anttiasmala Mar 5, 2024
e05d270
Changed if UUID is not a string now returns instantly the error inste…
anttiasmala Mar 5, 2024
d5355fc
Created simple error handler and added Prisma's 'record not found' er…
anttiasmala Mar 5, 2024
e07ab71
Changed errorFound to handleError
anttiasmala Mar 5, 2024
b3ed93c
Removed errorFound function. Replaced it with backend's handleError f…
anttiasmala Mar 5, 2024
3205825
Added an error if trying to send an invalid request body to server (i…
anttiasmala Mar 5, 2024
1ba1824
Created a new file HttpError.ts
anttiasmala Mar 7, 2024
eae2e85
Added a basic custom error class
anttiasmala Mar 7, 2024
22f7e9b
Added HttpError custom error to be recognized in handleError.ts
anttiasmala Mar 7, 2024
b1a9157
Made HttpError class exportable and imported it in handleError.ts
anttiasmala Mar 7, 2024
1f27b53
Added console.error if error was not validated
anttiasmala Mar 11, 2024
a8919c4
Added a check if error was related to Gift
anttiasmala Mar 11, 2024
958fb85
Changed error returns to throw an error instead
anttiasmala Mar 11, 2024
637fe9e
Created a new folder frontend. Added handleError.ts file
anttiasmala Mar 11, 2024
9a36949
Created a function handleGiftError and added the same error handling …
anttiasmala Mar 11, 2024
9b4353c
Changed 'own error handling' to a function
anttiasmala Mar 11, 2024
3483583
Moved handleError.ts to utils folder
anttiasmala Mar 13, 2024
5c0cd04
Fixed imports after move of handleError.ts
anttiasmala Mar 13, 2024
c282fe2
Made Prisma's error code P2025 to be generic
anttiasmala Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/handleError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { NextApiResponse } from 'next';

export function handleError(res: NextApiResponse, e: unknown) {
if (e instanceof PrismaClientKnownRequestError) {
if (e.code === 'P2025') {
return res.status(404).send('Gift was not found on the server!');
Copy link
Owner

Choose a reason for hiding this comment

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

Eikös tässä voi olla kyse myös Userista nyt kun se PR mergetty? Eli saako error-objektista jotenkin tietää kummasta on kyse? Jos ei, niin pitäisikö geneerisesti ilmoittaa, että "Object was not..." tms.?

}
}

return res.status(500).send('Server error!');
}
Loading
Loading