siesta swift - Response transformer exceptions -


with service i'm working with, of responses in xml, few plain text. what's best way set up?

currently have this:

// root should return plain text, don't try transform configuretransformer("/") { (content: string, entity) -> string? in   return content } // data xml configuretransformer("**") { (content: nsdata, entity) -> nsxmldocument? in   return try? nsxmldocument(data: content, options: 0) } configuretransformer("**/properties/*") {   (content: nsdata, entity) -> string? in   return string(data: content, encoding: nsutf8stringencoding) } 

..but when query root url, plain text, error because nsdata -> nsxmldocument transformer can't applied.

edit: maybe want apply xml transformer when content-type application/xml. there way that?

based on see in service.init(), did this, , it's working pretty well:

func xmlresponsetransformer(     transformerrors: bool = true) -> siesta.responsetransformer {   return siesta.responsecontenttransformer(transformerrors: transformerrors) {     (content: nsdata, entity: siesta.entity) throws -> nsxmldocument in     return try nsxmldocument(data: content, options: 0)   } }  configure(description: "xml") {   $0.config.pipeline[.parsing].add(xmlresponsetransformer(),                                    contenttypes: [ "*/xml" ]) } 

Comments