-
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
Conversation
…ad going through error found process
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
pages/api/gifts/[uuid].ts
Outdated
throw new Error('Invalid ID', { cause: 'idError' }); | ||
return res.status(400).send('Invalid ID'); |
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.
Tässä kohtaa mielestäni on turha heittää virhekoodia, koska emme kerää mitään dataa esimerkiksi virheiden määrästä tmv
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.
Se etu olisi heittää virhe, että silloin virheenkäsittely tapahtuisi kokonaisuudessaan samassa paikassa. Sitten jos esim. haluaa tulostaa virheistä tiedon serverin konsoliin, niin olisi helppoa kun tulostus riittäisi lisätä yhteen paikkaan ja saisi kerralla kaikki virheet hoidettua. Itse siis heittäisin tässä HttpError
virheen.
Olisiko järkevämpää käydä muita Prisman virhekoodeja läpi jo tässä vaiheessa vaiko vasta myöhemmin tarvittaessa? Nyt muut Prisman virhekoodit vain palauttavat Mulla on myös versio, jossa on oma CustomError, mutta en tiedä onko tarpeellinen vielä. Teen vaikka hiukan myöhemässä vaiheessa PR:n siitä Edit: Lisäsin oman CustomErrorin HttpError-nimellä |
…n POST or PUT request)
Ei kannata käydä muita Prisman virhekoodeja läpi, mutta kannattaa lisätä |
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.
Hyvältä näyttää, pari kommenttia.
backend/handleError.ts
Outdated
|
||
if (e instanceof PrismaClientKnownRequestError) { | ||
if (e.code === 'P2025') { | ||
return res.status(404).send('Gift was not found on the server!'); |
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.?
pages/api/gifts/[uuid].ts
Outdated
throw new Error('Invalid ID', { cause: 'idError' }); | ||
return res.status(400).send('Invalid ID'); |
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.
Se etu olisi heittää virhe, että silloin virheenkäsittely tapahtuisi kokonaisuudessaan samassa paikassa. Sitten jos esim. haluaa tulostaa virheistä tiedon serverin konsoliin, niin olisi helppoa kun tulostus riittäisi lisätä yhteen paikkaan ja saisi kerralla kaikki virheet hoidettua. Itse siis heittäisin tässä HttpError
virheen.
backend/handleError.ts
Outdated
if (e.meta?.modelName === 'Gift') { | ||
return res.status(404).send('Gift was not found on the server!'); | ||
} | ||
return res.status(404).send('Record was not found on the server!'); |
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.
Tekisin tästä geneerisen, joka toimii kaikilla modeleilla:
if (e.meta?.modelName === 'Gift') { | |
return res.status(404).send('Gift was not found on the server!'); | |
} | |
return res.status(404).send('Record was not found on the server!'); | |
const modelName = | |
typeof e.meta?.modelName === 'string' ? e.meta?.modelName : 'Record'; | |
return res.status(404).send(modelName + ' was not found on the server!'); |
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.
Vau! Tämä oli hyvä, kiitos!! Ei käynyt edes mielessä, vaikka hyvin simppeli tapa onkin 😄
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.
Valmis mergettäväksi! 💪
Tein muutaman pienen muutoksen koskien virhekoodeja / virheiden käsittelyä. En ollut tyytyväinen tuohon vanhaan tapaan, joten ajattelin hiukan päivittää sitä. Ei mitään isoja muutoksia, mutta jotain pientä