Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
marthendalnunes
left a comment
There was a problem hiding this comment.
Overall the changes are good, just check the proper error message handling and the optional helper function to keep your code cleaner :D
| discord || telegram || github || projectLink || aditionalInformation | ||
| ? 'Aditional information' | ||
| : '' | ||
| const discordHandle = discord ? `Discord handle: ${discord}` : '' |
There was a problem hiding this comment.
To keep it DRY, I recommend creating a helper function that takes the optional data variable and its message and returns an empty string, and replaces all of these ternary operators.
something like that
// Helper function that returns an empty string if the optional data is falsy
const handleOptionalData = (optionalData: string, message: string) => optionalData ? message : ''
// instead of
const discordHandle = discord ? `Discord handle: ${discord}` : ''
// replacing for
const discordHandle = handleOptionalData(discord, `Discord handle: ${discord}`)
| } catch (err) { | ||
| console.log(err) | ||
| res.status(400).json({ | ||
| success: false, | ||
| }) | ||
| } |
There was a problem hiding this comment.
In case of an error in the execution of the endpoint is always good to also send the error message. Getting the message with the correct typing from an error response is a bit tricky, but here's a solution:
| } catch (err) { | |
| console.log(err) | |
| res.status(400).json({ | |
| success: false, | |
| }) | |
| } | |
| } catch (err) { | |
| console.log(err) | |
| let message | |
| if (err instanceof Error) message = err.message | |
| else message = String(err) | |
| res.status(400).json({ | |
| success: false, | |
| message | |
| }) | |
| } |
|
|
||
| export const SubmitSchema = z.object({ | ||
| firstName: nonEmptyStringContraint, | ||
| email: nonEmptyStringContraint, |
There was a problem hiding this comment.
Zod string objects has a built-in method for checking the email syntax:
| email: nonEmptyStringContraint, | |
| email: nonEmptyStringContraint.email(), |
No description provided.