package org.thinkinghub.gateway.oauth.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.thinkinghub.gateway.oauth.exception.GatewayException;

import lombok.extern.slf4j.Slf4j;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandlingController {

	@ExceptionHandler({GatewayException.class})
	public String gatewayBusinessError(HttpServletRequest request, Exception exception){
		log.error("Request "+ request.getRequestURL() + " raised " + exception);
		return "gatewayerror";
	}
	
	@ExceptionHandler({SQLException.class})
	public String databaseError(HttpServletRequest request, Exception exception){
		log.error("Request "+ request.getRequestURL() + " raised " + exception);
		return "databaseerror";
	}
	
	@ExceptionHandler({IOException.class})
	public String IOError(HttpServletRequest request, Exception exception){
		log.error("Request "+ request.getRequestURL() + " raised " + exception);
		return "ioerror";
	}
}

@@ -150,16 +150,137 @@
 quest;%0A%0A
+import org.springframework.http.HttpStatus;%0Aimport org.springframework.web.bind.MissingServletRequestParameterException;%0A
 import o
@@ -401,16 +401,79 @@
 andler;%0A
+import org.springframework.web.bind.annotation.ResponseStatus;%0A
 import o
@@ -664,216 +664,832 @@
 er(%7B
-GatewayException.class%7D)%0A%09public String gatewayBusinessError(HttpServletRequest request, Exception exception)%7B%0A%09%09log.error(%22Request %22+ request.getRequestURL() + %22 raised %22 + exception);%0A%09%09return %22gatewayerror
+Exception.class, RuntimeException.class%7D)%0A%09@ResponseStatus(value=HttpStatus.BAD_REQUEST)%0A%09public String defaultError(HttpServletRequest request, Exception exception)%7B%0A%09%09log.error(%22Request %22+ request.getRequestURL() + %22 raised %22 + exception);%0A%09%09return %22An error happened%22;%0A%09%7D%0A%09%0A%09@ExceptionHandler(%7BGatewayException.class%7D)%0A%09public String gatewayError(HttpServletRequest request, Exception exception)%7B%0A%09%09log.error(%22Request %22+ request.getRequestURL() + %22 raised %22 + exception);%0A%09%09return %22gatewayerror%22;%0A%09%7D%0A%09%0A%09@ExceptionHandler(%7BMissingServletRequestParameterException.class%7D)%0A%09@ResponseStatus(value=HttpStatus.BAD_REQUEST)%0A%09public String requestParamError(HttpServletRequest request, Exception exception)%7B%0A%09%09log.error(%22Request %22+ request.getRequestURL() + %22 raised %22 + exception);%0A%09%09return %22Your request is missing parameter(s)
 %22;%0A%09
@@ -1773,18 +1773,18 @@
  String 
-IO
+io
 Error(Ht

add method to handle exception from Spring (MissingServletRequestParameterException)