Skip to content

Commit 122aed1

Browse files
committed
Show a user-friendly error message when RPC interactions fail
ref https://www.woltlab.com/community/thread/314577-gridview-interaction-wirft-keine-exception/
1 parent 2a6556f commit 122aed1

File tree

5 files changed

+67
-64
lines changed

5 files changed

+67
-64
lines changed

ts/WoltLabSuite/Core/Api/Result.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,36 @@ export async function fromInfallibleApiRequest<T = unknown>(request: () => Promi
105105
}
106106

107107
function showErrorDialog(apiError: ApiError): void {
108-
const code = escapeHTML(apiError.code);
109-
const type = escapeHTML(apiError.type);
110-
const message = apiError.message ? escapeHTML(apiError.message) : "(not set)";
111-
const param = apiError.param ? "<kbd>" + escapeHTML(apiError.param) + "</kbd>" : "(not set)";
112-
113-
const html = `
114-
<dl>
115-
<dt>Unexpected server error</dt>
116-
<dd><kbd>${type}</kbd></dd>
117-
</dl>
118-
<dl>
119-
<dt>Error code</dt>
120-
<dd><kbd>${code}</kbd></dd>
121-
</dl>
122-
<dl>
123-
<dt>Parameter</dt>
124-
<dd>${param}</dd>
125-
</dl>
126-
<dl>
127-
<dt>Message</dt>
128-
<dd>${message}</dd>
129-
</dl>
130-
`;
108+
let html = "";
109+
if ((!window.ENABLE_DEBUG_MODE && apiError.code === "permission_denied") || apiError.code === "assertion_failed") {
110+
html = getPhrase(
111+
apiError.code === "permission_denied" ? "wcf.ajax.error.permissionDenied" : "wcf.ajax.error.illegalLink",
112+
);
113+
} else {
114+
const code = escapeHTML(apiError.code);
115+
const type = escapeHTML(apiError.type);
116+
const message = apiError.message ? escapeHTML(apiError.message) : "(not set)";
117+
const param = apiError.param ? "<kbd>" + escapeHTML(apiError.param) + "</kbd>" : "(not set)";
118+
119+
html = `
120+
<dl>
121+
<dt>Unexpected server error</dt>
122+
<dd><kbd>${type}</kbd></dd>
123+
</dl>
124+
<dl>
125+
<dt>Error code</dt>
126+
<dd><kbd>${code}</kbd></dd>
127+
</dl>
128+
<dl>
129+
<dt>Parameter</dt>
130+
<dd>${param}</dd>
131+
</dl>
132+
<dl>
133+
<dt>Message</dt>
134+
<dd>${message}</dd>
135+
</dl>
136+
`;
137+
}
131138

132139
const dialog = dialogFactory().fromHtml(html).asAlert();
133140
dialog.show(getPhrase("wcf.global.error.title"));

ts/WoltLabSuite/Core/Component/Interaction/Rpc.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ async function handleRpcInteraction(
3232
}
3333

3434
if (confirmationType == ConfirmationType.Delete) {
35-
const result = await deleteObject(endpoint);
36-
if (!result.ok) {
37-
return;
38-
}
35+
(await deleteObject(endpoint)).unwrap();
3936
} else {
40-
const result = await postObject(
41-
endpoint,
42-
confirmationResult.reason ? { reason: confirmationResult.reason } : undefined,
43-
);
44-
if (!result.ok) {
45-
return;
46-
}
37+
(
38+
await postObject(endpoint, confirmationResult.reason ? { reason: confirmationResult.reason } : undefined)
39+
).unwrap();
4740
}
4841

4942
if (interactionEffect === InteractionEffect.ReloadItem || interactionEffect === InteractionEffect.ReloadPage) {

wcfsetup/install/files/js/WoltLabSuite/Core/Api/Result.js

Lines changed: 28 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Rpc.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ final class PreloadPhrasesCollectingListener
1616
{
1717
public function __invoke(PreloadPhrasesCollecting $event): void
1818
{
19+
$event->preload('wcf.ajax.error.illegalLink');
20+
$event->preload('wcf.ajax.error.permissionDenied');
21+
1922
$event->preload('wcf.button.delete.confirmMessage');
2023

2124
$event->preload('wcf.clipboard.item.mark');

0 commit comments

Comments
 (0)