What controls the 'severity' of ApexPages.addMessages(exception)?
Try catching errors as below :
catch(Exception e)
{
String error = e.getMessage();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,error));
}
Instead of just doing ApexPages.addMessages(e);
Using this in conjunction with Apexpages.hasMessages()
if(some_condition){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Info not an error'));
}
if(ApexPages.hasMessages(ApexPages.Severity.Info)){
// do something
}
To set severity dynamically I would use getTypeName()
and create a map/ custom setting with exception key and severity value
http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_classes_exception_methods.htm
Here are some examples of how to add messages with different severities and how they are outputted:
Confirm/Success:
ApexPages.addMessage(
new ApexPages.Message(ApexPages.Severity.Confirm,'Sample Success Message'));
Warning:
ApexPages.addMessage(
new ApexPages.Message(ApexPages.Severity.Warning,'Sample Warning Message'));
Informational:
ApexPages.addMessage(
new ApexPages.Message(ApexPages.Severity.Info,'Sample Informational Message'));
Error:
ApexPages.addMessage(
new ApexPages.Message(ApexPages.Severity.Error,'Sample Error Message'));
There's a great answer in this question that has lots more detail: Difference between the multiple messaging options in Visualforce?