Skip to content

Commit ab93ea4

Browse files
committed
Improve handling error in ncs.
1 parent 38375da commit ab93ea4

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.graphqlncs
2+
3+
import graphql.ErrorClassification
4+
import graphql.ErrorType
5+
6+
7+
open class ExpTy(
8+
errorMessage: String? = "",
9+
private val parameters: Map<String, Any>? = mutableMapOf()
10+
) : GraphQLException(errorMessage) {
11+
override val message: String?
12+
get() = super.message
13+
14+
override fun getExtensions(): MutableMap<String, Any> {
15+
return mutableMapOf("parameters" to (parameters ?: mutableMapOf()))
16+
}
17+
18+
override fun getErrorType(): ErrorClassification {
19+
return ErrorType.ValidationError
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.graphqlncs;
2+
3+
import graphql.ErrorClassification;
4+
import graphql.GraphQLError;
5+
import graphql.language.SourceLocation;
6+
7+
import java.util.List;
8+
9+
public class GraphQLException extends RuntimeException implements GraphQLError {
10+
11+
String customMessage;
12+
13+
public GraphQLException(String customMessage) {
14+
this.customMessage = customMessage;
15+
}
16+
17+
@Override
18+
public String getMessage() {
19+
return customMessage;
20+
}
21+
22+
@Override
23+
public List<SourceLocation> getLocations() {
24+
return null;
25+
}
26+
27+
@Override
28+
public ErrorClassification getErrorType() {
29+
return null;
30+
}
31+
}

jdk_8_maven/cs/graphql/graphql-ncs/src/main/kotlin/org/graphqlncs/resolver/QueryResolver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.graphqlncs.resolver
22

33
import graphql.kickstart.tools.GraphQLQueryResolver
44
import org.graphqlncs.Exep
5+
import org.graphqlncs.ExpTy
56
import org.graphqlncs.type.*
67
import org.springframework.http.ResponseEntity
78
import org.springframework.stereotype.Component
@@ -36,14 +37,14 @@ open class QueryResolver(
3637
fun remainder(a: Int, b:Int ): Int {
3738
val lim = 10000
3839
return if (a > lim || a < -lim || b > lim || b < -lim) {
39-
throw Exep("400")
40+
throw ExpTy("400")
4041
} else remainder.exe(a, b)
4142
}
4243

4344
fun bessj(n:Int, x:Double ): Double {
4445

4546
return if (n <= 2 || n > 1000) {
46-
throw Exep("400")
47+
throw ExpTy("400")
4748

4849
} else
4950
bessj.bessj(n, x)

0 commit comments

Comments
 (0)