java - Spring Boot - catch all error controller for all 404 errors? (Multi Tenant specific?) -
i implement simple error controller within spring boot app handles 404 errors. have 1 now, won't catch errors "/" after initial error. example:
myapp.localhost/asdflas - caught controller
myapp.localhost/asdflas/sadfdsfd - not handled correctly.
i have multi-tenant spring boot app, need pass in variables error.html template in order process custom properties. currently, simple errors working fine.
i'm sure following code have not correct, current "errorhandingcontroller" class looks this:
@controller public class errorhandlingcontroller implements errorcontroller { @autowired private environment environment; @autowired private errorattributes errorattributes; @autowired private saleservice saleservice; @autowired private operatorservice operatorservice; @autowired private appproperties appproperties; public void setappproperties(appproperties appproperties) { this.appproperties = appproperties; } @override public string geterrorpath() { return "/error"; } @requestmapping(value = {"/error/**", "error", "/error"}, produces = "text/html; charset=utf-8") public string errorgeneric(modelmap modelmap) { string tenantname = tenantcontext.getcurrenttenant(); string thisurl = environment.getproperty("server.address") + ":" + environment.getproperty("local.server.port"); receiptconfig receiptproperties = operatorservice.getoperatorproperty(); tenantdto tenantdto = operatorservice.getoperatorinfo(saleservice.getoperatorid(tenantcontext.getcurrenttenant())); if (tenantdto.gettenantcode() == null) return "redirect:http://" + thisurl; modelmap.addattribute("tenant", tenantdto); modelmap.addattribute("receiptproperties", receiptproperties); modelmap.addattribute("url", "http://" + receiptproperties.geturl() + "." + thisurl); return "error"; } }
is approach correct or way off? (i'm guessing way off..)
Comments
Post a Comment