GithubHelp home page GithubHelp logo

Comments (2)

trizz avatar trizz commented on June 30, 2024 1

Hi Matt,

There is currently no way to access request data. However, when something goes wrong, a ValidationException is returned when the validation fails. If something went wrong that is not a validation error, a more generic PowerdnsException will be thrown. You are correct that you are getting an exception which can be caught.

So, to answer your question you can catch one, or both, exceptions in your controller:

public function myFancyControllerFuntion() {
    try {
        $powerdns->createZone($domain, $nameServers)->create($dnsRecords);
    } catch (\Exonet\Powerdns\Exceptions\ValidationException $validationException) {
        // The PowerDNS validation error is set as message on the exception:
        return myViewRender('dns-validation-error', ['error-message' => $validationException->getMessage()]);
    } catch (\Exonet\Powerdns\Exceptions\PowerdnsException $powerDnsException) {
        // The PowerDNS validation error is set as message on the exception:
        return myViewRender('dns-error', ['error-message' => $powerDnsException->getMessage()]);
    }

    return myViewRender('dns-success', 'DNS Zone was created!');
}

Or, if you just want a single catch block:

public function myFancyControllerFuntion() {
    try {
        $powerdns->createZone($domain, $nameServers)->create($dnsRecords);
    } catch (\Exonet\Powerdns\Exceptions\PowerdnsException $powerDnsException) {
        // The ValidationException extends the PowerdnsException, so cachting the PowerdnsException will handle both exceptions.
        return myViewRender('dns-error', ['error-message' => $powerDnsException->getMessage()]);
    }

    return myViewRender('dns-success', 'DNS Zone was created!');
}

In this example I've used a fake function myViewRender but you can of course add any logic you'd like, such as setting variables or other data.

from powerdns-php.

matt-smartlabs avatar matt-smartlabs commented on June 30, 2024

@trizz Thank you very much for your help!! That's amazing it's working how I wanted :)

from powerdns-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.