diff --git a/nodes/src/main/java/io/aexp/nodes/graphql/internal/CustomError.java b/nodes/src/main/java/io/aexp/nodes/graphql/internal/CustomError.java new file mode 100644 index 0000000..c9c6882 --- /dev/null +++ b/nodes/src/main/java/io/aexp/nodes/graphql/internal/CustomError.java @@ -0,0 +1,42 @@ +package io.aexp.nodes.graphql.internal; + +import java.util.List; +import java.util.Map; + +public class CustomError { + + private Map extensions; + private String errorType; + private List path; + + public Map getExtensions() { + return extensions; + } + + public void setExtensions(Map extensions) { + this.extensions = extensions; + } + + public String getErrorType() { + return errorType; + } + + public void setErrorType(String errorType) { + this.errorType = errorType; + } + + public List getPath() { + return path; + } + + public void setPath(List path) { + this.path = path; + } + + @Override + public String toString() { + return "extensions=" + extensions + + ", errorType=" + errorType + + ", path=" + path; + } +} diff --git a/nodes/src/main/java/io/aexp/nodes/graphql/internal/Error.java b/nodes/src/main/java/io/aexp/nodes/graphql/internal/Error.java index c4f1a00..b90cd27 100644 --- a/nodes/src/main/java/io/aexp/nodes/graphql/internal/Error.java +++ b/nodes/src/main/java/io/aexp/nodes/graphql/internal/Error.java @@ -15,7 +15,7 @@ import java.util.Arrays; -public final class Error { +public final class Error extends CustomError { private String message; private Location[] locations; diff --git a/nodes/src/test/java/io/aexp/nodes/graphql/internal/CustomErrorTest.java b/nodes/src/test/java/io/aexp/nodes/graphql/internal/CustomErrorTest.java new file mode 100644 index 0000000..4fa5868 --- /dev/null +++ b/nodes/src/test/java/io/aexp/nodes/graphql/internal/CustomErrorTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018 American Express Travel Related Services Company, Inc. + * + * Licensed 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 io.aexp.nodes.graphql.internal; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + +public class CustomErrorTest { + + @Test + public void errorTest() { + Map extensions = new HashMap(); + extensions.put("400", "Bad Request"); + CustomError customError = new CustomError(); + customError.setErrorType("DataFetchingException"); + customError.setExtensions(extensions); + customError.setPath(null); + assertNull(customError.getPath()); + assertEquals("DataFetchingException", customError.getErrorType()); + assertEquals(extensions, customError.getExtensions()); + } +}