@@ -117,4 +117,72 @@ class ErrorProcessorTest {
117
117
assertThat(errorInfo.errorMessage).contains(" HTTP 404" )
118
118
assertThat(errorInfo.githubError).isNull()
119
119
}
120
+
121
+ @Test
122
+ fun `getDetailedError - given HttpException with JSON github errors list - returns ErrorInfo processed data with errors` () {
123
+ // language=JSON
124
+ val jsonErrorBody =
125
+ """
126
+ {
127
+ "message": "Validation Failed",
128
+ "errors": [
129
+ {
130
+ "message": "The listed users cannot be searched either because the users do not exist or you do not have permission to view the users.",
131
+ "resource": "Search",
132
+ "field": "q",
133
+ "code": "invalid"
134
+ }
135
+ ],
136
+ "documentation_url": "https://docs.github.com/v3/search/",
137
+ "status": "422"
138
+ }
139
+ """ .trimIndent()
140
+ val httpException = HttpException (Response .error<Any >(422 , jsonErrorBody.toResponseBody(" application/json" .toMediaTypeOrNull())))
141
+ val errorProcessor = ErrorProcessor ()
142
+
143
+ val errorInfo = errorProcessor.getDetailedError(httpException)
144
+
145
+ assertThat(errorInfo).isInstanceOf(ErrorInfo ::class .java)
146
+ assertThat(errorInfo.githubError?.message).isEqualTo(" Validation Failed" )
147
+ assertThat(errorInfo.githubError?.status).isEqualTo(422 )
148
+ assertThat(errorInfo.githubError?.errors).isNotEmpty()
149
+
150
+ val githubErrorDetail = errorInfo.githubError?.errors?.get(0 )!!
151
+ assertThat(
152
+ githubErrorDetail.message,
153
+ ).isEqualTo(
154
+ " The listed users cannot be searched either because the users do not exist or you do not have permission to view the users." ,
155
+ )
156
+ assertThat(githubErrorDetail.resource).isEqualTo(" Search" )
157
+ assertThat(githubErrorDetail.field).isEqualTo(" q" )
158
+ assertThat(githubErrorDetail.code).isEqualTo(" invalid" )
159
+ }
160
+
161
+ @Test
162
+ fun `getDetailedError - given HttpException with JSON github error user not found - validates user not found` () {
163
+ // language=JSON
164
+ val jsonErrorBody =
165
+ """
166
+ {
167
+ "message": "Validation Failed",
168
+ "errors": [
169
+ {
170
+ "message": "The listed users cannot be searched either because the users do not exist or you do not have permission to view the users.",
171
+ "resource": "Search",
172
+ "field": "q",
173
+ "code": "invalid"
174
+ }
175
+ ],
176
+ "documentation_url": "https://docs.github.com/v3/search/",
177
+ "status": "422"
178
+ }
179
+ """ .trimIndent()
180
+ val httpException = HttpException (Response .error<Any >(422 , jsonErrorBody.toResponseBody(" application/json" .toMediaTypeOrNull())))
181
+ val errorProcessor = ErrorProcessor ()
182
+
183
+ val errorInfo = errorProcessor.getDetailedError(httpException)
184
+
185
+ assertThat(errorInfo).isInstanceOf(ErrorInfo ::class .java)
186
+ assertThat(ErrorProcessor .isUserMissingError(errorInfo.githubError)).isTrue()
187
+ }
120
188
}
0 commit comments