swagception icon indicating copy to clipboard operation
swagception copied to clipboard

Handling exceptions with $I and $S

Open mlambley opened this issue 7 years ago • 0 comments

A better framework around catching the myriad exceptions and updating $I and $S for each of them.

Currently looks like:

try {
    //Stuff
} catch (\Swagception\Exception\NoPathHandlerException $e) {
    //We don't have a path handler configured for this path.
    $I->fail($e->getMessage());
    return;
} catch (\Swagception\Exception\ValidationException $e) {
    //Swagger validation error, eg. something was a string when we were expecting an integer.
    $I->fail($e->getMessage());
    return;
} catch (\Swagception\Exception\ResponseEmptyException $e) {
    //If we can't find any data, we still test that the root route works and returns an empty array.
    $S->skip($e->getMessage());
    return;
} catch (\IncorrectBuildException $e) {
    //Only available in certain builds.
    $S->skip($e->getMessage());
    return;
} catch (\NoEntityException $e) {
    //Could not find any data to test.
    $S->skip($e->getMessage());
    return;
} catch (\RestWorkflowException $e) {
    //Could not find any data, incorrect build, etc.
    $S->skip($e->getMessage());
    return;
}

Some of them are parent classes of others and their functionalities overlap. This can get very horrible very quickly.

Perhaps an interface which will have a number of functions which accept $I, $S, and the details of the error. Then there will be a clear, fixed definition of what the errors are.

mlambley avatar Jul 26 '18 01:07 mlambley