Skip to content

Commit

Permalink
fixed error displaying on create
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Sep 20, 2024
1 parent bebbb85 commit cf6070e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app/workshop/[id]/client_code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,11 @@ const EditElement = ({ bandage, onClose }: { bandage: Interfaces.Bandage, onClos
return;
}
if (response.status === 400) {
alert(response.data.message.map((str: string) => capitalize(str)).join(', '));
if (typeof response.data.message === 'object') {
alert(response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`);
} else {
alert(response.data.message_ru || response.data.message);
}
}
})
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/workshop/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ const Editor = ({ onBandageChange, onColorChange, onColorableChange, onBandageCh
if (response.status !== 201) {
const error_el = document.getElementById('create_error') as HTMLLabelElement;
if (error_el) {
error_el.innerText = response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`;
if (typeof response.data.message === 'object') {
error_el.innerText = response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`;
} else {
error_el.innerText = response.data.message_ru || response.data.message;
}
}
} else {
router.replace(`/workshop/${response.data.external_id}`);
Expand All @@ -259,7 +263,7 @@ const Editor = ({ onBandageChange, onColorChange, onColorableChange, onBandageCh
heightVal={height} />
</>
}
<p id="error" style={{ margin: 0, color: "rgb(247 22 22)" }}></p>
<p id="error" style={{ margin: 0, color: "#dc2626" }}></p>
<textarea maxLength={50} id="title" placeholder="Заголовок" className={style.textarea} onInput={(ev) => setTitle((ev.target as HTMLTextAreaElement).value)} value={title} />
<textarea maxLength={300} placeholder="Описание" className={style.textarea} onInput={(ev) => setDescription((ev.target as HTMLTextAreaElement).value)} value={description} />

Expand All @@ -275,7 +279,7 @@ const Editor = ({ onBandageChange, onColorChange, onColorableChange, onBandageCh
<CategorySelector enabledCategories={enabledCategories}
allCategories={allCategories}
onChange={setCategories} />
<label id="create_error" style={{ margin: 0, color: "rgb(247 22 22)" }}></label>
<label id="create_error" style={{ margin: 0, color: "#dc2626" }}></label>
<button onClick={() => create()} className={style.skin_load}>Создать</button>
</div>
);
Expand Down

0 comments on commit cf6070e

Please sign in to comment.