You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/04/17 17:26:40 UTC
[23/51] [abbrv] incubator-usergrid git commit: [USERGRID-538] -
improve error response for uncaught errors
[USERGRID-538] - improve error response for uncaught errors
Add time uuid to error response to track the error from logs
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/79d7ec61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/79d7ec61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/79d7ec61
Branch: refs/heads/two-dot-o-import
Commit: 79d7ec615b7db81ed30acb501b580644f50818a9
Parents: da8d7b6
Author: Senthil Kumar K <se...@gmail.com>
Authored: Thu Apr 2 20:28:09 2015 -0700
Committer: Senthil Kumar K <se...@gmail.com>
Committed: Thu Apr 2 20:38:11 2015 -0700
----------------------------------------------------------------------
.../org/apache/usergrid/rest/ApiResponse.java | 50 +++++++++++++-------
.../exceptions/AbstractExceptionMapper.java | 11 ++---
.../rest/exceptions/UncaughtException.java | 36 ++++++++++++++
3 files changed, 74 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79d7ec61/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
index d7dd5f8..590dabf 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
@@ -23,27 +23,27 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.UUID;
-
-import javax.xml.bind.annotation.XmlAnyElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.persistence.AggregateCounterSet;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.rest.exceptions.UncaughtException;
import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
import org.apache.usergrid.services.ServiceRequest;
import org.apache.usergrid.services.ServiceResults;
import org.apache.usergrid.utils.InflectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
-import org.apache.commons.lang.ClassUtils;
-import org.apache.commons.lang.StringUtils;
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.UUID;
import static org.apache.usergrid.utils.InflectionUtils.pluralize;
@@ -62,6 +62,7 @@ public class ApiResponse {
private String errorUri;
private String exception;
private String callback;
+ private UUID errorId;
private String path;
private String uri;
@@ -163,12 +164,18 @@ public class ApiResponse {
code = exceptionToErrorCode( e );
}
error = code;
- errorDescription = description;
- if ( e != null ) {
- if ( description == null ) {
- errorDescription = e.getMessage();
+ if ( e instanceof UncaughtException ) {
+ errorId = ((UncaughtException) e).getTimeUUID();
+ errorDescription = "Internal Server Error";
+ exception = UncaughtException.class.getName();
+ } else {
+ errorDescription = description;
+ if (e != null) {
+ if (description == null) {
+ errorDescription = e.getMessage();
+ }
+ exception = e.getClass().getName();
}
- exception = e.getClass().getName();
}
}
@@ -204,6 +211,15 @@ public class ApiResponse {
this.errorUri = errorUri;
}
+ @JsonProperty( "error_id" )
+ @JsonSerialize( include = Inclusion.NON_NULL )
+ public UUID getErrorId() {
+ return errorId;
+ }
+
+ public void setErrorId(UUID errorId) {
+ this.errorId = errorId;
+ }
@JsonSerialize( include = Inclusion.NON_NULL )
public String getException() {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79d7ec61/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
index 3f5dda6..15e2468 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
@@ -17,6 +17,10 @@
package org.apache.usergrid.rest.exceptions;
+import org.apache.usergrid.rest.ApiResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
@@ -24,14 +28,9 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.rest.ApiResponse;
-
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
-
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.apache.usergrid.rest.utils.JSONPUtils.isJavascript;
import static org.apache.usergrid.rest.utils.JSONPUtils.wrapJSONPResponse;
@@ -57,7 +56,7 @@ public abstract class AbstractExceptionMapper<E extends java.lang.Throwable> imp
@Override
public Response toResponse( E e ) {
// if we don't know what type of error it is then it's a 500
- return toResponse( INTERNAL_SERVER_ERROR, e );
+ return toResponse( INTERNAL_SERVER_ERROR, (E) new UncaughtException(e) );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79d7ec61/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UncaughtException.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UncaughtException.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UncaughtException.java
new file mode 100644
index 0000000..3e06a5b
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UncaughtException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.usergrid.rest.exceptions;
+
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import java.util.UUID;
+
+public class UncaughtException extends Throwable {
+
+ private UUID timeUUID;
+
+ public UncaughtException(Throwable cause) {
+ super(cause);
+ this.timeUUID = UUIDGenerator.newTimeUUID();
+ }
+
+ public UUID getTimeUUID() {
+ return timeUUID;
+ }
+}