Skip to content

Commit

Permalink
Merge pull request #137 from rundeck/issue/136
Browse files Browse the repository at this point in the history
Fix #136 parse error with 500 response for project delete
  • Loading branch information
gschueler authored Dec 14, 2017
2 parents a2e47a4 + 0ca7afb commit a014cd9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ErrorResponse implements ErrorDetail {
@Attribute
public int apiversion;

@Attribute(name = "code")
@Attribute(name = "code", required = false)
@Path("error")
public String errorCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.rundeck.client.api.model

import okhttp3.MediaType
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
import spock.lang.Specification

import java.lang.annotation.Annotation

/**
* @author greg
* @since 12/13/17
*/
class ErrorResponseSpec extends Specification {
def "xml parse code not required"() {
given:
def retrofit = new Retrofit.Builder().baseUrl('http://test').
addConverterFactory(SimpleXmlConverterFactory.create()).
build()

when:
Converter<ResponseBody, ErrorResponse> converter = retrofit.responseBodyConverter(
ErrorResponse.class,
[] as Annotation[],
);
ErrorResponse result = converter.convert(ResponseBody.create(MediaType.parse('application/xml'), xmlText))

then:

result != null
result.errorCode == code
result.error == error
result.message == message
result.apiVersion == version

where:
xmlText |
code |
error |
message | version
'<result error=\'true\' apiversion=\'20\'><error><message>blah</message></error></result>' |
null |
'true' |
'blah' | 20
'<result error=\'true\' apiversion=\'20\'><error code=\'xyz\'><message>blah</message></error></result>' |
'xyz' |
'true' |
'blah' | 20

}
}

0 comments on commit a014cd9

Please sign in to comment.