-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #130 static content exception handling
- Loading branch information
1 parent
909c6a4
commit 6ba5573
Showing
7 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
java/registry/src/main/java/io/opensaber/registry/controller/BaseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.opensaber.registry.controller; | ||
|
||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.opensaber.registry.exception.CustomException; | ||
import io.opensaber.registry.middleware.util.Constants; | ||
|
||
@RestController | ||
public class BaseController implements ErrorController { | ||
|
||
private static final String PATH = "/error"; | ||
|
||
@RequestMapping(value = PATH) | ||
public String error() throws Exception { | ||
throw new CustomException(Constants.CUSTOM_EXCEPTION_ERROR); | ||
} | ||
|
||
@Override | ||
public String getErrorPath() { | ||
return PATH; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
java/registry/src/main/java/io/opensaber/registry/exception/CustomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.opensaber.registry.exception; | ||
|
||
public class CustomException extends Exception { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -4024691757405373470L; | ||
|
||
public CustomException(String message){ | ||
super(message); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
java/registry/src/main/java/io/opensaber/registry/exception/CustomExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.opensaber.registry.exception; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.servlet.HandlerExceptionResolver; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import io.opensaber.registry.interceptor.handler.BaseResponseHandler; | ||
import io.opensaber.registry.middleware.util.Constants; | ||
|
||
public class CustomExceptionHandler extends BaseResponseHandler implements HandlerExceptionResolver { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class); | ||
|
||
private Gson gson; | ||
|
||
public CustomExceptionHandler(Gson gson){ | ||
this.gson = gson; | ||
} | ||
|
||
@Override | ||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, | ||
Exception ex) { | ||
try{ | ||
logger.info("Exception thrown-"+ex.getMessage()); | ||
setResponse(response); | ||
writeResponseObj(gson, Constants.CUSTOM_EXCEPTION_ERROR); | ||
response = getResponse(); | ||
}catch(Exception e){ | ||
logger.error("Error in sending response"); | ||
} | ||
return null; | ||
} | ||
|
||
} |
File renamed without changes.