Skip to content

Commit

Permalink
errors is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
shayypy committed Jul 7, 2023
1 parent 68f10c6 commit 30b67dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions modules/editor/webhook/DiscordErrorsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function DiscordErrorsModal(props: DiscordErrorsModalProps) {
const flattened = errors.map(discordError => {
const flattenErrorObject = (d: DiscordError["errors"], key?: string) => {
const items: string[][] = []
for (const [k, v] of Object.entries(d)) {
for (const [k, v] of Object.entries(d!)) {
const newKey = key ? `${key}.${k}` : k

if (typeof v === "object" && !Array.isArray(v) && v != null) {
Expand All @@ -44,8 +44,11 @@ export function DiscordErrorsModal(props: DiscordErrorsModalProps) {

return items
}
const items = flattenErrorObject(discordError.errors)
return items.map(([k, v]) => `In \`${k}\`: ${v}`)
if (discordError.errors) {
const items = flattenErrorObject(discordError.errors)
return items.map(([k, v]) => `In \`${k}\`: ${v}`)
}
return [discordError.message]
})[0]

return (
Expand Down
2 changes: 1 addition & 1 deletion types/DiscordError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export type DiscordError = {
code: number
message: string
errors: Record<string, unknown>
errors?: Record<string, unknown>
}

export type CodedError = {
Expand Down

0 comments on commit 30b67dc

Please sign in to comment.