// Path: src/main/java/yourwebproject2/framework/api/APIResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class APIResponse {
//     public static final String API_RESPONSE = "apiResponse";
//     Object result;
//     String time;
//     long code;
// 
//     public static class ExceptionAPIResponse extends APIResponse {
//         Object details;
// 
//         public Object getDetails() {
//             return details;
//         }
// 
//         public void setDetails(Object details) {
//             this.details = details;
//         }
//     }
// 
//     public Object getResult() {
//         return result;
//     }
// 
//     public void setResult(Object result) {
//         this.result = result;
//     }
// 
//     public String getTime() {
//         return time;
//     }
// 
//     public void setTime(String time) {
//         this.time = time;
//     }
// 
//     public long getCode() {
//         return code;
//     }
// 
//     public void setCode(long code) {
//         this.code = code;
//     }
// 
//     public static APIResponse toOkResponse(Object data) {
//         return toAPIResponse(data, 200);
//     }
// 
//     public static APIResponse toErrorResponse(Object data) {
//         return toAPIResponse(data, 2001);
//     }
// 
//     public static ExceptionAPIResponse toExceptionResponse(String result, Object details) {
//         ExceptionAPIResponse response = new ExceptionAPIResponse();
//         response.setResult(result);
//         response.setDetails(details);
//         response.setCode(2001);
//         return response;
//     }
// 
//     public APIResponse withModelAndView(ModelAndView modelAndView) {
//         modelAndView.addObject(API_RESPONSE, this);
//         return this;
//     }
// 
//     public static APIResponse toAPIResponse(Object data, long code) {
//         APIResponse response = new APIResponse();
//         response.setResult(data);
//         response.setCode(code);
//         return response;
//     }
// }
// 
// Path: src/main/java/yourwebproject2/framework/controller/BaseController.java
// public abstract class BaseController {
//     protected static final String JSON_API_CONTENT_HEADER = "Content-type=application/json";
// 
//     public String extractPostRequestBody(HttpServletRequest request) throws IOException {
//         if ("POST".equalsIgnoreCase(request.getMethod())) {
//             Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
//             return s.hasNext() ? s.next() : "";
//         }
//         return "";
//     }
// 
//     public JSONObject parseJSON(String object) {
//         return new JSONObject(object);
//     }
// 
//     public void decorateUserDTOWithCredsFromAuthHeader(String authHeader, UserDTO userDTO) {
//         String[] basicAuth = authHeader.split(" ");
//         Validate.isTrue(basicAuth.length == 2, "the auth header is not splittable with space");
//         Validate.isTrue(basicAuth[0].equalsIgnoreCase("basic"), "not basic auth: "+basicAuth[0]);
//         Validate.isTrue(Base64.isBase64(basicAuth[1].getBytes()), "encoded value not base64");
// 
//         String decodedAuthHeader = new String(Base64.decode(basicAuth[1].getBytes()));
//         String[] creds = decodedAuthHeader.split(":");
//         Validate.isTrue(creds.length == 2, "the creds were not concatenated using ':', could not split the decoded header");
// 
//         userDTO.setEmail(creds[0]);
//         userDTO.setPassword(creds[1]);
//     }
// }


import yourwebproject2.framework.api.APIResponse;
import yourwebproject2.framework.controller.BaseController;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
package yourwebproject2.controller;



/**
 * @author: kameshr
 */
@Controller
public class ErrorController extends BaseController {
    private static Logger LOG = LoggerFactory.getLogger(ErrorController.class);

    @RequestMapping("error")
// Path: src/main/java/yourwebproject2/framework/api/APIResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class APIResponse {
//     public static final String API_RESPONSE = "apiResponse";
//     Object result;
//     String time;
//     long code;
// 
//     public static class ExceptionAPIResponse extends APIResponse {
//         Object details;
// 
//         public Object getDetails() {
//             return details;
//         }
// 
//         public void setDetails(Object details) {
//             this.details = details;
//         }
//     }
// 
//     public Object getResult() {
//         return result;
//     }
// 
//     public void setResult(Object result) {
//         this.result = result;
//     }
// 
//     public String getTime() {
//         return time;
//     }
// 
//     public void setTime(String time) {
//         this.time = time;
//     }
// 
//     public long getCode() {
//         return code;
//     }
// 
//     public void setCode(long code) {
//         this.code = code;
//     }
// 
//     public static APIResponse toOkResponse(Object data) {
//         return toAPIResponse(data, 200);
//     }
// 
//     public static APIResponse toErrorResponse(Object data) {
//         return toAPIResponse(data, 2001);
//     }
// 
//     public static ExceptionAPIResponse toExceptionResponse(String result, Object details) {
//         ExceptionAPIResponse response = new ExceptionAPIResponse();
//         response.setResult(result);
//         response.setDetails(details);
//         response.setCode(2001);
//         return response;
//     }
// 
//     public APIResponse withModelAndView(ModelAndView modelAndView) {
//         modelAndView.addObject(API_RESPONSE, this);
//         return this;
//     }
// 
//     public static APIResponse toAPIResponse(Object data, long code) {
//         APIResponse response = new APIResponse();
//         response.setResult(data);
//         response.setCode(code);
//         return response;
//     }
// }
// 
// Path: src/main/java/yourwebproject2/framework/controller/BaseController.java
// public abstract class BaseController {
//     protected static final String JSON_API_CONTENT_HEADER = "Content-type=application/json";
// 
//     public String extractPostRequestBody(HttpServletRequest request) throws IOException {
//         if ("POST".equalsIgnoreCase(request.getMethod())) {
//             Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
//             return s.hasNext() ? s.next() : "";
//         }
//         return "";
//     }
// 
//     public JSONObject parseJSON(String object) {
//         return new JSONObject(object);
//     }
// 
//     public void decorateUserDTOWithCredsFromAuthHeader(String authHeader, UserDTO userDTO) {
//         String[] basicAuth = authHeader.split(" ");
//         Validate.isTrue(basicAuth.length == 2, "the auth header is not splittable with space");
//         Validate.isTrue(basicAuth[0].equalsIgnoreCase("basic"), "not basic auth: "+basicAuth[0]);
//         Validate.isTrue(Base64.isBase64(basicAuth[1].getBytes()), "encoded value not base64");
// 
//         String decodedAuthHeader = new String(Base64.decode(basicAuth[1].getBytes()));
//         String[] creds = decodedAuthHeader.split(":");
//         Validate.isTrue(creds.length == 2, "the creds were not concatenated using ':', could not split the decoded header");
// 
//         userDTO.setEmail(creds[0]);
//         userDTO.setPassword(creds[1]);
//     }
// }


// Path: src/main/java/yourwebproject2/controller/ErrorController.java
import yourwebproject2.framework.api.APIResponse;
import yourwebproject2.framework.controller.BaseController;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

package yourwebproject2.controller;



/**
 * @author: kameshr
 */
@Controller
public class ErrorController extends BaseController {
    private static Logger LOG = LoggerFactory.getLogger(ErrorController.class);

    @RequestMapping("error")
    public @ResponseBody  APIResponse customError(HttpServletRequest request, HttpServletResponse response) {