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(OpencastErrorType errorType) {
38      this.errorType = errorType;
39    }
40  
41    public GraphQLRuntimeException(String message, OpencastErrorType errorType) {
42      super(message);
43      this.errorType = errorType;
44    }
45  
46    public GraphQLRuntimeException(String message, OpencastErrorType errorType, Throwable cause) {
47      super(message, cause);
48      this.errorType = errorType;
49    }
50  
51    public GraphQLRuntimeException(String message, Map<String,Object> extensions, Throwable cause) {
52      super(message, cause);
53      this.errorType = OpencastErrorType.Undefined;
54      this.extensions = extensions;
55    }
56  
57    public GraphQLRuntimeException(String message, OpencastErrorType errorType, Map<String,Object> extensions,
58        Throwable cause) {
59      super(message, cause);
60      this.errorType = errorType;
61      this.extensions = extensions;
62    }
63  
64    public GraphQLRuntimeException(Throwable cause) {
65      super(cause);
66      this.errorType = OpencastErrorType.InternalError;
67    }
68  
69    public GraphQLRuntimeException(OpencastErrorType errorType, Throwable cause) {
70      super(cause);
71      this.errorType = errorType;
72    }
73  
74    @Override
75    public List<SourceLocation> getLocations() {
76      return null;
77    }
78  
79    public ErrorClassification getErrorType() {
80      return errorType;
81    }
82  
83    @Override
84    public List<Object> getPath() {
85      return GraphQLError.super.getPath();
86    }
87  
88    @Override
89    public Map<String, Object> toSpecification() {
90      return GraphQLError.super.toSpecification();
91    }
92  
93    public Map<String, Object> getExtensions() {
94      return extensions;
95    }
96  
97  }