Skip to content

Commit f373ffc

Browse files
committed
feat: show error modal on request error
1 parent e3d1a94 commit f373ffc

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ckanext/blocksmith/assets/js/blocksmith-editor.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,10 @@ ckan.module("blocksmith-editor", function ($) {
239239
'X-CSRFToken': csrf_token
240240
},
241241
success: (resp) => {
242-
if (resp.success) {
243-
window.location.href = this.sandbox.client.url(resp.result.url);
244-
} else {
245-
console.error(resp);
246-
}
242+
window.location.href = this.sandbox.client.url(resp.result.url);
243+
},
244+
error: (resp) => {
245+
this._showErrorModal(resp);
247246
}
248247
});
249248
},
@@ -328,6 +327,25 @@ ckan.module("blocksmith-editor", function ($) {
328327
*/
329328
_onUrlBlur: function (e) {
330329
e.target.value = this._slugify(e.target.value);
331-
}
330+
},
331+
332+
/**
333+
* Show an error modal.
334+
*
335+
* @param {object} resp
336+
*/
337+
_showErrorModal: function (resp) {
338+
const modal = this.editor.Modal;
339+
modal.setTitle('Save Error');
340+
modal.setContent(`
341+
<div style="padding: 10px;">
342+
<p><strong>There was a problem saving the page.</strong></p>
343+
<pre style="background: white; color: black; padding: 10px; border-radius: 3px;">
344+
${JSON.stringify(resp.responseJSON, null, 2)}
345+
</pre>
346+
</div>
347+
`);
348+
modal.open();
349+
},
332350
}
333351
});

0 commit comments

Comments
 (0)