解決策は非常に簡単です。AlfrescoRuntimeException
メッセージを添えて投げるだけ。
throw new AlfrescoRuntimeException("your.message");
その場合、メッセージが表示されますが、例外のサブタイプが失われます。
屋外の javaScript コードで例外処理を見たときの驚きを言葉で説明するのは非常に困難です。
onFormSubmitFailure: function FormManager_onFormSubmitFailure(response)
{
var failureMsg = null;
if (response.json && response.json.message && response.json.message.indexOf("Failed to persist field 'prop_cm_name'") !== -1)
{
failureMsg = this.msg("message.details.failure.name");
}
else if (response.json && response.json.message && response.json.message.indexOf("PropertyValueSizeIsMoreMaxLengthException") !== -1)
{
failureMsg = this.msg("message.details.failure.more.max.length");
}
else if (response.json && response.json.message && response.json.message.indexOf("org.alfresco.error.AlfrescoRuntimeException") == 0)
{
var split = response.json.message.split(/(?:org.alfresco.error.AlfrescoRuntimeException:\s*\d*\s*)/ig);
if (split && split[1])
{
failureMsg = split[1];
}
}
Alfresco.util.PopupManager.displayPrompt(
{
title: this.msg(this.options.failureMessageKey),
text: failureMsg ? failureMsg : (response.json && response.json.message ? response.json.message : this.msg("message.details.failure"))
});
},
ご覧のとおり、Java からクラス名を「キャッチ」し、それをメッセージに置き換えます。カスタム例外を処理するためのより拡張可能な方法を提供してくれることを願っています。
PSもちろん、別の方法は、ファイルを拡張して、例外の条件をalfresco.js
もう1つ追加することです。if else