metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
210 stars 155 forks source link

Get reason from error when an exception is thrown #194

Closed joveice closed 5 years ago

joveice commented 5 years ago

I believe it's related / the same as #149 Tho the xml responses look different When I get an exception I'm not able to grab the reason behind it from the eppException which is thrown.

Is it possible to get this implemented / or if there already is one?

Hope you do not mind me mentioning you since you had much control on Norid. @alexrsagen if you know something about this?

Etc

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ietf:params:xml:ns:epp-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
  <response>
    <result code="2308">
      <msg>Data management policy violation</msg>
    </result>
    <extension>
      <conditions xmlns="http://www.norid.no/xsd/no-ext-result-1.0" xsi:schemaLocation="http://www.norid.no/xsd/no-ext-result-1.0 no-ext-result-1.0.xsd">
        <condition code="EC004033" severity="error">
          <msg>Name and identity mismatch</msg>
          <details>The contact name [Wrong company name] is not consistent with data from Enhetsregisteret (Correct company name).</details>
        </condition>
      </conditions>
    </extension>
    <trID>
      <clTRID>something</clTRID>
      <svTRID>something</svTRID>
    </trID>
  </response>
</epp>

and a multi one

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ietf:params:xml:ns:epp-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
  <response>
    <result code="2308">
      <msg>Data management policy violation</msg>
    </result>
    <extension>
      <conditions xmlns="http://www.norid.no/xsd/no-ext-result-1.0" xsi:schemaLocation="http://www.norid.no/xsd/no-ext-result-1.0 no-ext-result-1.0.xsd">
        <condition code="EC004021" severity="error">
          <msg>Missing identity</msg>
          <details>The field 'no-ext-contact:identity' is required for a contact of type [person].</details>
        </condition>
        <condition code="EC004036" severity="error">
          <msg>Org field not allowed</msg>
          <details>Field [org] is not allowed for [person] contacts.</details>
        </condition>
      </conditions>
    </extension>
    <trID>
      <clTRID>something</clTRID>
      <svTRID>something</svTRID>
    </trID>
  </response>
</epp>
alexrsagen commented 5 years ago

For Norid-specific "conditions", see getExt... functions here. This response trait is included in all responses to Norid-specific requests, not generic EPP requests. https://github.com/metaregistrar/php-epp-client/blob/4fad2531e74e49fcf20a5e96178324e82e728090/Protocols/EPP/eppExtensions/no-ext-result-1.0/eppResponses/noridEppResponseTrait.php#L6-L45

Otherwise if you are after the RFC5730 <epp:result> content, see getResult... functions here. https://github.com/metaregistrar/php-epp-client/blob/4fad2531e74e49fcf20a5e96178324e82e728090/Protocols/EPP/eppResponses/eppResponse.php#L213-L296

joveice commented 5 years ago

@alexrsagen Not sure how I should do that, this is what throws the exception

$response = $conn->request($contact);

So I tried to catch it on that, but I'm not able to assign my $response when the exception is thrown?

metaregistrar commented 5 years ago

you could make an extra try/catch block around the part that throws the exception that you specifically want to catch...

alexrsagen commented 5 years ago

Right. An eppException is thrown whenever the status code is non-successful, which is not really helpful for trying to get the actual reason behind it.

Here is a function of eppException which lets you get a custom-formatted string of the EPP error message (not Norid-specific conditions) https://github.com/metaregistrar/php-epp-client/blob/4fad2531e74e49fcf20a5e96178324e82e728090/Protocols/EPP/eppException.php#L55-L60

This function is responsible for throwing the eppException. https://github.com/metaregistrar/php-epp-client/blob/4fad2531e74e49fcf20a5e96178324e82e728090/Protocols/EPP/eppResponses/eppResponse.php#L120-L195

If you want to get the Norid-specific conditions, we may have to modify eppException to allow you to still get the response through a method.

joveice commented 5 years ago

@metaregistrar Not sure what you meant there?

@alexrsagen Yea I tried the getReason but it's not set so it only contains a null. I guess a modify will be needed? I don't know whats best practice here for clean code nor do I have time to look at it right now as I need to finish the functional part of what I'm working on before "nice to have" can come.

alexrsagen commented 5 years ago

Yeah, no wonder it's null. getReason returns the value of <epp:reason>, which is not provided by Norid.

https://github.com/metaregistrar/php-epp-client/blob/4fad2531e74e49fcf20a5e96178324e82e728090/Protocols/EPP/eppResponses/eppResponse.php#L233-L238

Will have to add some kind of a function like getResponse so you can still get the response. I'm busy right now, so I can't do that for you.

joveice commented 5 years ago

Okey, well I don't need it now, it's just nice to have, I don't have access to Norid at private so I can't really do much there. I'll see if I can do it when I'm done, trying to improve security is pri 1.

joveice commented 5 years ago

I can't really find a good way to implement this, I tried to just include the response with the exception, but I don't know if this is a good way to do it, we probably would like a norid specific way for this and not a global one right?

alexrsagen commented 5 years ago

A global method named getResponse on eppException would be fine. Should add the original eppResponse instance to the eppException whenever an error is thrown from the Success method.

joveice commented 5 years ago

Okey, I made that pr, works out great if I just search the xpath after the exception is thrown.