View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.graphql.exception;
23  
24  import java.util.List;
25  import java.util.Map;
26  
27  import graphql.ErrorClassification;
28  import graphql.GraphQLError;
29  import graphql.language.SourceLocation;
30  
31  public class GraphQLRuntimeException extends RuntimeException implements GraphQLError {
32    private static final long serialVersionUID = 7752209655703366697L;
33  
34    private final OpencastErrorType errorType;
35    private Map<String,Object> extensions;
36  
37    public GraphQLRuntimeException(Throwable cause) {
38      super(cause);
39      this.errorType = OpencastErrorType.InternalError;
40    }
41  
42    public GraphQLRuntimeException(String message) {
43      super(message);
44      this.errorType = OpencastErrorType.InternalError;
45    }
46  
47    public GraphQLRuntimeException(OpencastErrorType errorType) {
48      this.errorType = errorType;
49    }
50  
51    public GraphQLRuntimeException(OpencastErrorType errorType, Throwable cause) {
52      super(cause);
53      this.errorType = errorType;
54    }
55  
56    public GraphQLRuntimeException(String message, OpencastErrorType errorType) {
57      super(message);
58      this.errorType = errorType;
59    }
60  
61    public GraphQLRuntimeException(String message, OpencastErrorType errorType, Throwable cause) {
62      super(message, cause);
63      this.errorType = errorType;
64    }
65  
66    public GraphQLRuntimeException(String message, OpencastErrorType errorType, Map<String,Object> extensions) {
67      super(message);
68      this.errorType = errorType;
69      this.extensions = extensions;
70    }
71  
72    public GraphQLRuntimeException(String message, OpencastErrorType errorType, Map<String,Object> extensions,
73        Throwable cause) {
74      super(message, cause);
75      this.errorType = errorType;
76      this.extensions = extensions;
77    }
78  
79    public GraphQLRuntimeException(String message, Map<String,Object> extensions) {
80      super(message);
81      this.errorType = OpencastErrorType.Undefined;
82      this.extensions = extensions;
83    }
84  
85    public GraphQLRuntimeException(String message, Map<String,Object> extensions, Throwable cause) {
86      super(message, cause);
87      this.errorType = OpencastErrorType.Undefined;
88      this.extensions = extensions;
89    }
90  
91    @Override
92    public List<SourceLocation> getLocations() {
93      return null;
94    }
95  
96    public ErrorClassification getErrorType() {
97      return errorType;
98    }
99  
100   @Override
101   public List<Object> getPath() {
102     return GraphQLError.super.getPath();
103   }
104 
105   @Override
106   public Map<String, Object> toSpecification() {
107     return GraphQLError.super.toSpecification();
108   }
109 
110   public Map<String, Object> getExtensions() {
111     return extensions;
112   }
113 
114 }