該解決方案非常簡單。只需將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看他們「抓」類名稱和消息替換它。我希望他們提供更可擴展的方式來處理客戶的例外情況。
P.S.當然,另一種方法是擴展alfresco.js
文件併爲您例外添加一個if else
條件。
您是否嘗試使用'getMessage()'獲取消息,而不是在異常處調用'toString()'? – Gagravarr