Skip to content

Commit 5acf7a1

Browse files
committed
fix for NCS-graphql
1 parent ab93ea4 commit 5acf7a1

5 files changed

Lines changed: 50 additions & 67 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

jdk_8_maven/cs/graphql/graphql-ncs/src/main/kotlin/org/graphqlncs/GraphQLException.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.graphqlncs
2+
23
import org.springframework.boot.SpringApplication
34
import org.springframework.boot.autoconfigure.SpringBootApplication
45

56

6-
77
@SpringBootApplication
88
open class NcsApplication
99

10-
1110
/*
1211
API accessible at
1312
http://localhost:8080/graphql

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

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.graphqlncs.resolver
22

3+
import graphql.ErrorType
4+
import graphql.GraphQLError
35
import graphql.kickstart.tools.GraphQLQueryResolver
4-
import org.graphqlncs.Exep
5-
import org.graphqlncs.ExpTy
6+
import graphql.language.SourceLocation
67
import org.graphqlncs.type.*
7-
import org.springframework.http.ResponseEntity
88
import org.springframework.stereotype.Component
99

10+
1011
@Component
1112
open class QueryResolver(
1213
private val triangleClassification: TriangleClassification,
@@ -27,6 +28,10 @@ open class QueryResolver(
2728
}
2829

2930
fun fisher(m: Int, n: Int, x:Double ): Double {
31+
32+
if(m > 1000 || n > 1000){
33+
throw CustomException(400, "Invalid input")
34+
}
3035
return fisher.exe(m, n, x)
3136
}
3237

@@ -36,17 +41,51 @@ open class QueryResolver(
3641

3742
fun remainder(a: Int, b:Int ): Int {
3843
val lim = 10000
39-
return if (a > lim || a < -lim || b > lim || b < -lim) {
40-
throw ExpTy("400")
41-
} else remainder.exe(a, b)
44+
if (a > lim || a < -lim || b > lim || b < -lim)
45+
throw CustomException(400, "Invalid input")
46+
47+
return remainder.exe(a, b)
4248
}
4349

4450
fun bessj(n:Int, x:Double ): Double {
4551

46-
return if (n <= 2 || n > 1000) {
47-
throw ExpTy("400")
52+
if (n <= 2 || n > 1000) {
53+
throw CustomException(400, "Invalid input")
54+
}
4855

49-
} else
50-
bessj.bessj(n, x)
56+
return bessj.bessj(n, x)
5157
}
58+
}
59+
60+
/**
61+
* This does not fully work... but at least we get:
62+
*
63+
* "Unexpected error occurred"
64+
*
65+
* instead of:
66+
*
67+
* "Internal Server Error(s)..."
68+
*/
69+
class CustomException(private val errorCode: Int, errorMessage: String) : RuntimeException(errorMessage), GraphQLError {
70+
71+
override fun getExtensions(): Map<String, Any?>? {
72+
val customAttributes: MutableMap<String, Any?> = LinkedHashMap()
73+
customAttributes["errorCode"] = errorCode
74+
customAttributes["errorMessage"] = message
75+
return customAttributes
76+
}
77+
78+
override fun getLocations(): List<SourceLocation>? {
79+
return null
80+
}
81+
82+
override fun getErrorType(): ErrorType? {
83+
return ErrorType.ValidationError
84+
}
85+
86+
@Suppress("ACCIDENTAL_OVERRIDE")
87+
override fun getMessage(): String? {
88+
return message
89+
}
90+
5291
}

0 commit comments

Comments
 (0)