bet365 / soap

Make it easy to use SOAP from Erlang
Apache License 2.0
200 stars 74 forks source link

Parsing error messages #29

Open des75 opened 6 years ago

des75 commented 6 years ago

Hi, I use the library to consume SOAP service and when error 500 occurres, the XML returns as string, like following:

{:error,
 {:client,
  {:parsing_message, 500,
   [{'connection', 'close'}, {'date', 'Mon, 21 Aug 2017 09:13:58 GMT'},
    {'server', 'serverName'}, {'content-length', '525'},
    {'content-type', 'text/xml;charset=utf-8'}], :error, :function_clause}},
 "<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault xmlns:ns4=\"http://www.w3.org/2003/05/soap-envelope\"><faultcode>S:Server</faultcode><faultstring>FailtString</faultstring><detail><ns2:RecordName xmlns:ns2=\"http://soap.url\"><errorCode>NOT_FOUND</errorCode><message>Error Message</message></ns2:RecordName></detail></S:Fault></S:Body></S:Envelope>"}

There is generated record for fault message, but it is not used.

-record('P:RecordName ', {
    errorCode :: string() | undefined,
    message :: string() | undefined}).

How to make it parse XML into a erlang records when SOAP service returns an error?

deadtrickster commented 6 years ago

After further debugging it turned out current version can't process complex detail tags. Only strings. I think they even hard-coded.

-record(faultdetail, {uri :: string(),
                      tag :: string(),
                      text :: string()}).
deadtrickster commented 6 years ago

https://github.com/bet365/soap/blob/9e1ae526bd0078ea1d1509e20ae49f46f2efb841/src/soap_fault.hrl#L27

deadtrickster commented 6 years ago

Addressed here: https://github.com/deadtrickster/soap/commit/1b85a239457e0944a75a4423105a21ed151edb04

What's missing:

  1. operations generated have set faults to empty list/undefined;
  2. faults (and perhaps responses in generatal) aren't validated that they actually the responses/faults for this particular operation;
  3. no 1.2 support.