-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b62d95c
Updated packages
anttiasmala db6e3e6
Created a new folder backend. Created a file called handleError.ts
anttiasmala e05d270
Changed if UUID is not a string now returns instantly the error inste…
anttiasmala d5355fc
Created simple error handler and added Prisma's 'record not found' er…
anttiasmala e07ab71
Changed errorFound to handleError
anttiasmala b3ed93c
Removed errorFound function. Replaced it with backend's handleError f…
anttiasmala 3205825
Added an error if trying to send an invalid request body to server (i…
anttiasmala 1ba1824
Created a new file HttpError.ts
anttiasmala eae2e85
Added a basic custom error class
anttiasmala 22f7e9b
Added HttpError custom error to be recognized in handleError.ts
anttiasmala b1a9157
Made HttpError class exportable and imported it in handleError.ts
anttiasmala 1f27b53
Added console.error if error was not validated
anttiasmala a8919c4
Added a check if error was related to Gift
anttiasmala 958fb85
Changed error returns to throw an error instead
anttiasmala 637fe9e
Created a new folder frontend. Added handleError.ts file
anttiasmala 9a36949
Created a function handleGiftError and added the same error handling …
anttiasmala 9b4353c
Changed 'own error handling' to a function
anttiasmala 3483583
Moved handleError.ts to utils folder
anttiasmala 5c0cd04
Fixed imports after move of handleError.ts
anttiasmala c282fe2
Made Prisma's error code P2025 to be generic
anttiasmala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | ||
} | ||
} | ||
|
||
return res.status(500).send('Server error!'); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
User
ista 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.?