javascript - unable to forward to the error page when any exception is occured -


i working on springmvc , angular application. when ever exception occurs need forward error page, below scenario not forwarding error page instead redirecting page page blank , when checked browser console, below exception mentioned:

failed load resource: server responded status of 404 () :8080/undefined 

instead of returning page , showing blank page, want forward error page. have exception handler class in exception, exception occurred handler class called , handles , forwards error page.

js code:

myapp.controller('mycontroller', function ($rootscope, $scope, $sce, myservice, $window) {     $scope.getdata = function () {          $scope.pdfname = {};         $scope.html = '';        myservice.getmydata($scope.id1).then(             function (response) {                 $scope.myresponse = response;                 //check error                 if ($scope.myresponse .error) {                     $rootscope.showerror(500, $scope.myresponse .error);                 } else {                 if(window.navigator.mssaveoropenblob){                     $scope.iebrowser = true;                     //logic here                     } else {                     $scope.iebrowser = false;                     //some logic here}             }},          function (errresponse) {             alert("in error ds");             $rootscope.showerror(500, errresponse);             $scope.pdfname = {};          });     }     $scope.getmydata(); }); 

//exception handler class

@controlleradvice public class myexceptioncontrolleradvice {      @exceptionhandler(exception.class)     public @responsebody  errorinfobean exception(exception e) {         system.out.println("in exceptioncontrolleradvice!----  " +e.getmessage());         errorinfobean error = new errorinfobean();         error.setstatus(500);         error.seterror(e.getmessage());         return error;     } } 

from spring controller when exception occurred hitting above myexceptioncontrolleradvice class not returning error page. tried changing 500 404 in above myexceptioncontrolleradvice didn't worked.

web.xml: have configured below:

<error-page>         <error-code>500</error-code>         <location>/views/error.jsp</location>     </error-page>     <error-page>         <exception-type>404</exception-type>         <location>/views/error.jsp</location>     </error-page> 

404 error occur because of page not found or bad url. using spring controller , rest services, nee use request mapping of controller , method. need use @requestmapping annotation before class , method.

@requestmapping("/myexceptionclass") public class  @requestmapping(value = "/exceptio", method = requestmethod.post, produces = "application/json", consumes = "application/json") public restresponse save(){  } 

so url : localhost:8080/projectname/myexceptionclass/exception


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -