Giter Site home page Giter Site logo

Acme HTTP Errors about acme HOT 9 CLOSED

barryvdh avatar barryvdh commented on May 29, 2024
Acme HTTP Errors

from acme.

Comments (9)

kelunik avatar kelunik commented on May 29, 2024

BadCsrException, BadNonceException, ConnectException, DnssecException, MalformedRequestException, InternalServerException, TlsException, UnauthorizedException, UnknownHostException.

I'm not happy with some of these names, do you have suggestions?

from acme.

kelunik avatar kelunik commented on May 29, 2024

Another alternative would be to return the type in AcmeException::getCode.

from acme.

staabm avatar staabm commented on May 29, 2024

I agree that all of those errors should be represented by 1 class (not 1 each) which then provides a method to further determine the underlying error

from acme.

kelunik avatar kelunik commented on May 29, 2024

I have improved the error messages, please review d3805a6.

from acme.

barryvdh avatar barryvdh commented on May 29, 2024

What about doing the type/detail handling inside the exception?

You can change the Exception constructor when extending, for example to typehint a Response object. You can then apply the same logic in your Eception.
You could also create a static factory for your AcmeException, to create on from a Response.

class AcmeException extends Exception {
    public function __construct($message, Response $response = null, Exception $previous = null)
    {
        parent::__construct($message, 0, $previous);

        if ($response) {
            $info = json_decode($response->getBody(), true);

            if ($info && isset($info['type'], $info['detail'])) {
                $this->code = $info['type'];
                $this->message .= ' ' . $info['detail'];
            }
        }

    }
}

https://3v4l.org/WgOnF

from acme.

kelunik avatar kelunik commented on May 29, 2024

Should the default error code be internal, generic, general or unknown?

from acme.

barryvdh avatar barryvdh commented on May 29, 2024

Don't know, could just leave it 0, the Exception default.

from acme.

kelunik avatar kelunik commented on May 29, 2024

Can I close this?

from acme.

barryvdh avatar barryvdh commented on May 29, 2024

Hmm, using a string as code might give unexpected results when stacking exceptions, see: zenire/da-letsencrypt#40
Testcase: https://3v4l.org/ObN47

from acme.

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.