Repository: incubator-atlas Updated Branches: refs/heads/0.8-incubating f454e7a44 -> 4baa23f1c
ATLAS-1611: incorrect error code for negative tests (#2) (cherry picked from commit 89a387279d9d0cae66f8e0a75a9ee3610da8c173) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/2cf954a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/2cf954a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/2cf954a4 Branch: refs/heads/0.8-incubating Commit: 2cf954a4994c1b3c089a2fd0b1166da8589b23b5 Parents: f454e7a Author: Madhan Neethiraj <[email protected]> Authored: Fri Mar 10 14:36:14 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Fri Mar 17 00:35:00 2017 -0700 ---------------------------------------------------------------------- intg/src/main/java/org/apache/atlas/AtlasErrorCode.java | 4 +++- .../repository/converters/AtlasInstanceConverter.java | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/2cf954a4/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java index 69c201d..5054cf0 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -67,6 +67,7 @@ public enum AtlasErrorCode { INSTANCE_LINEAGE_INVALID_PARAMS(400, "ATLAS-400-00-026", "Invalid lineage query parameters passed {0}: {1}"), ATTRIBUTE_UPDATE_NOT_SUPPORTED(400, "ATLAS-400-00-027", "{0}.{1} : attribute update not supported"), INVALID_VALUE(400, "ATLAS-400-00-028", "invalid value: {0}"), + BAD_REQUEST(400, "ATLAS-400-00-020", "{0}"), // All Not found enums go here TYPE_NAME_NOT_FOUND(404, "ATLAS-404-00-001", "Given typename {0} was invalid"), @@ -78,11 +79,12 @@ public enum AtlasErrorCode { CLASSIFICATION_NOT_FOUND(404, "ATLAS-404-00-008", "Given classification {0} was invalid"), INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND(404, "ATLAS-404-00-009", "Instance {0} with unique attribute {1} does not exist"), REFERENCED_ENTITY_NOT_FOUND(404, "ATLAS-404-00-00A", "Referenced entity {0} is not found"), + INSTANCE_NOT_FOUND(404, "ATLAS-404-00-00B", "Given instance is invalid/not found: {0}"), // All data conflict errors go here TYPE_ALREADY_EXISTS(409, "ATLAS-409-00-001", "Given type {0} already exists"), TYPE_HAS_REFERENCES(409, "ATLAS-409-00-002", "Given type {0} has references"), - INSTANCE_ALREADY_EXISTS(409, "ATLAS-409-00-003", "Given entity {0} already exists"), + INSTANCE_ALREADY_EXISTS(409, "ATLAS-409-00-003", "failed to update entity: {0}"), // All internal errors go here INTERNAL_ERROR(500, "ATLAS-500-00-001", "Internal server error {0}"), http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/2cf954a4/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java index a4f99a5..6e0766d 100644 --- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java +++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java @@ -45,6 +45,7 @@ import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Struct; +import org.apache.atlas.typesystem.exception.EntityExistsException; import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.TraitNotFoundException; import org.apache.atlas.typesystem.exception.TypeNotFoundException; @@ -199,19 +200,23 @@ public class AtlasInstanceConverter { } public static AtlasBaseException toAtlasBaseException(AtlasException e) { + if (e instanceof EntityExistsException) { + return new AtlasBaseException(AtlasErrorCode.INSTANCE_ALREADY_EXISTS, e.getMessage()); + } + if ( e instanceof EntityNotFoundException || e instanceof TraitNotFoundException) { - return new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, e); + return new AtlasBaseException(AtlasErrorCode.INSTANCE_NOT_FOUND, e.getMessage()); } if ( e instanceof TypeNotFoundException) { - return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e); + return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e.getMessage()); } if (e instanceof ValueConversionException) { return new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, e, e.getMessage()); } - return new AtlasBaseException(e); + return new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); }
