Skip to content

Add own exceptions to the library #37

Open

Description

@jaimeperez

While trying to add more meaningful messages to some of the typical errors, I've noticed that at some points in the library we are throwing simple exceptions with a message that's not really descriptive of the real problem, nor even translated. For instance, in \SAML2\SOAP::receive():

        $postText = file_get_contents('php://input');

        if (empty($postText)) {
            throw new Exception('Invalid message received to AssertionConsumerService endpoint.');
        }

or in \SAML2\Binding::getCurrentBinding():

        throw new Exception('Unable to find the current binding.');

If these were custom exceptions, we could capture them easily and display a meaningful, translated error message to the user, depending on where we are. Therefore I think we should even move some of the exceptions in SimpleSAMLphp to this library, and extend them with specific ones.

Activity

  1. relaxnow commented on Mar 20, 2015

    @relaxnow
    Contributor

    Good point!

  2. jaimeperez commented on Mar 20, 2015

    @jaimeperez
    MemberAuthor

    If only I could find time to do all the stuff I need to do... 😢

  3. salvorapi commented on Nov 27, 2017

    @salvorapi

    +1

  4. tvdijen commented on Jan 16, 2022

    @tvdijen
    Member

    Much work has been done.. Some left;

    grep -R "throw new Exception" * --exclude-dir=vendor

  5. tvdijen commented on Oct 24, 2022

    @tvdijen
  6. tvdijen commented on Mar 14, 2023

    @tvdijen
    Member

    Update:

    src/SAML2/Response/Validation/ConstraintValidator/DestinationMatches.php:            throw new Exception('No destination set in the response.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Unable to send artifact without a datastore configured.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Cannot get redirect URL, no Issuer set in the message.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Cannot get redirect URL, no destination set in the message.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Missing SAMLart parameter.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('No metadata found for remote provider with SHA1 ID: ' . var_export($sourceId, true));
    src/SAML2/HTTPArtifact.php:            throw new Exception('No ArtifactResolutionService with the correct index.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Received error from ArtifactResolutionService.');
    src/SAML2/HTTPArtifact.php:            throw new Exception('Empty ArtifactResponse received, maybe a replay?');
    src/SAML2/HTTPPost.php:                throw new Exception('Cannot send message, no destination set.');
    src/SAML2/HTTPPost.php:            throw new Exception('Missing SAMLRequest or SAMLResponse parameter.');
    src/SAML2/HTTPRedirect.php:                throw new Exception('Cannot build a redirect URL, no destination set.');
    src/SAML2/HTTPRedirect.php:            throw new Exception('Missing SAMLRequest or SAMLResponse parameter.');
    src/SAML2/HTTPRedirect.php:            throw new Exception(sprintf('Unknown SAMLEncoding: %s', $query['SAMLEncoding']));
    src/SAML2/HTTPRedirect.php:            throw new Exception('Error while base64 decoding SAML message.');
    src/SAML2/HTTPRedirect.php:            throw new Exception('Error while inflating SAML message.');
    src/SAML2/HTTPRedirect.php:            throw new Exception('Missing signature algorithm.');
    src/SAML2/SOAP.php:                throw new Exception('No destination available for SOAP message.');
    src/SAML2/SOAPClient.php:            throw new Exception('Cannot send SOAP message, no destination set.');
    src/SAML2/SOAPClient.php:            throw new Exception('Empty SOAP response, check peer certificate.');
    src/SAML2/SOAPClient.php:            throw new Exception(
    src/SAML2/SOAPClient.php:            throw new Exception('Unable to get key details from XMLSecurityKey.');
    src/SAML2/SOAPClient.php:            throw new Exception('Missing key in public key details.');
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions