Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better processing of JSON error responses in Http Response body #206

Open
martinda opened this issue Jan 4, 2022 · 0 comments
Open

Better processing of JSON error responses in Http Response body #206

martinda opened this issue Jan 4, 2022 · 0 comments
Assignees

Comments

@martinda
Copy link
Collaborator

martinda commented Jan 4, 2022

I would like better processing of JSON error responses. Currently when the error response is in the body of the Http response, it is not processed as json, it is stored as plain text in the exception message. This means that the user code has to parse the exception error message in order to extract the real error message. It would be easier if the json body was processed so users would not have to do it.

Here is an example. The request:

org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Sending request -1829602346: POST http://127.0.0.1:8080/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/revoke HTTP/1.1
jclouds.wire - >> "tokenUuid="
jclouds.headers - >> POST http://127.0.0.1:8080/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/revoke HTTP/1.1
jclouds.headers - >> Accept: application/json
jclouds.headers - >> Authorization: Basic YWRtaW46YWRtaW4=
jclouds.headers - >> Jenkins-Crumb: ea6c09c3fcf0a7638d58096d11fbc608fa8f05dcf02b3072bd75ef38a9e61f36
jclouds.headers - >> Cookie: JSESSIONID.f870fd5d=node08g9exl9u4f7516eqezzki3jhz8.node0; Path=/; HttpOnly
jclouds.headers - >> Content-Type: application/x-www-form-urlencoded
jclouds.headers - >> Content-Length: 10

The response:

org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Receiving response -1829602346: HTTP/1.1 400 Bad Request
jclouds.headers - << HTTP/1.1 400 Bad Request
jclouds.headers - << Server: Jetty(9.4.39.v20210325)
jclouds.headers - << X-Content-Type-Options: nosniff
jclouds.headers - << Cache-Control: must-revalidate,no-cache,no-store
jclouds.headers - << Content-Type: application/json
jclouds.headers - << Content-Length: 161
jclouds.wire - << "{[\n]"
jclouds.wire - << ""servlet":"Stapler",[\n]"
jclouds.wire - << ""message":"The tokenUuid cannot be empty",[\n]"
jclouds.wire - << ""url":"/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/revoke",[\n]"
jclouds.wire - << ""status":"400"[\n]"
jclouds.wire - << "}"

Currently, this is handled in JenkinsErrorHandler.java. The whole message is stored in the ErrorsHolder of RequestStatus as a plain text message. It looks like this:

    RequestStatus{value=false, errors=[Error{context=null, message={
    "servlet":"Stapler",
    "message":"The tokenUuid cannot be empty",
    "url":"/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/revoke",
    "status":"400"
    }, exceptionName=java.lang.IllegalArgumentException}]}

According to this conversation, the json would be the same for all Jetty based installations.

@cdancy cdancy self-assigned this Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants