java - Returning error list in jersey rest service -
in our project using rest service(jersey). in 1 of requirement return list of missing mandatory parameters client. right using exception mapper can return single error message,
public class mandatoryparametermissingexception extends runtimeexception { private static final long serialversionuid = 1l; public mandatoryparametermissingexception(string message) { super(message); } public class mandatoryparammissingexceptionmapper implements exceptionmapper<mandatoryparametermissingexception> { @override public response toresponse(mandatoryparametermissingexception ex) { errormessage errormessage = new errormessage(ex.getmessage(), 404, "document source:todo"); return response.status(status.not_found) .entity(errormessage) .build(); } private string errormessage; private int errorcode; private string documentation; public errormessage() { } public errormessage(string errormessage, int errorcode, string documentation) { super(); this.errormessage = errormessage; this.errorcode = errorcode; this.documentation = documentation; }
..getter setters
if find missing mandatory params, right doing like,
if (emailid == null) { throw new mandatoryparametermissingexception("email id missing"); }
could 1 please suggest best way enhance take list of error messages , pass client?
for issue created class called validationexception. validationexception contains list of validationerror.
there different kind of validationerror, example outofrangeerror, mandatoryparametererror , whatever need. validationerror contains specific attributes (all client needs create meaningful messagetext user) => mandatoryparametererror name of field, outofrangeerror name of field , allowed range.
on serverside there validators (in common package, client validation itself)... validators creating validationerrors during validation of data. if there validation errors, validationexception thrown. that's it. can give codesnippets...
Comments
Post a Comment