From de6122fa31998bf591b48c73c325fc502a1b1837 Mon Sep 17 00:00:00 2001
From: apoorvnaik <anaik@hortonworks.com>
Date: Wed, 7 Dec 2016 13:54:12 -0800
Subject: [PATCH] ATLAS-1355: Fix for bad error translation from V2 API

---
 release-log.txt                                                        | 1 +
 webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java | 6 ++++++
 webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java          | 8 +++-----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/release-log.txt b/release-log.txt
index c4d2a49..5a87d9b 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
 ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
 
 ALL CHANGES:
+ATLAS-1355: Fix for bad error translation from V2 API (apoorvnaik via sumasai)
 ATLAS-1351 HiveHook fails with NPE for hive process registration (vimalsharma via sumasai)
 ATLAS-1342 Titan Solrclient - Add timeouts for zookeeper connect and session (sumasai)
 ATLAS-1353 Invalid error message(500 internal server error) for lineage query on non-existing table. (sumasai)
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
index 355fb8d..9acfb2f 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
@@ -121,6 +121,9 @@ public class TypesResource {
         } catch (IllegalArgumentException e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
+        } catch (WebApplicationException e) {
+            LOG.error("Unable to persist types due to V2 API error", e);
+            throw e;
         } catch (Throwable e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
@@ -168,6 +171,9 @@ public class TypesResource {
         } catch (AtlasException | IllegalArgumentException e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
+        } catch (WebApplicationException e) {
+            LOG.error("Unable to persist types due to V2 API error", e);
+            throw e;
         } catch (Throwable e) {
             LOG.error("Unable to persist types", e);
             throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
index 867307f..43414c9 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
@@ -18,7 +18,6 @@
 package org.apache.atlas.web.rest;
 
 import com.google.inject.Inject;
-
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.SearchFilter;
 import org.apache.atlas.model.typedef.AtlasClassificationDef;
@@ -38,9 +37,6 @@ import org.apache.http.annotation.Experimental;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-import java.util.Set;
-
 import javax.inject.Singleton;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
@@ -54,6 +50,8 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Set;
 
 
 @Path("v2/types")
@@ -457,7 +455,7 @@ public class TypesREST {
         try {
             ret = typeDefStore.updateTypesDef(typesDef);
         } catch (AtlasBaseException ex) {
-            throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.NOT_MODIFIED));
+            throw new WebApplicationException(Servlets.getErrorResponse(ex, ex.getAtlasErrorCode().getHttpCode()));
         }
 
         return ret;
--
libgit2 0.27.1