Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Exceptions/Data/FoundTooManyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Exceptions\Data;

/**
* Use this exception when the data requested by your code was found and it found actually more than expected. A good
* use for this is the findSingle usual function we find in many library and orm. If you have more than 1 record
* found, it might mean that you should send back this exception.
*
* If the code in context is a service provider that queries a database, this would be the right exception to throw
* and listen for. The controller on the other hand would catch this and throw a NotFoundException from the Http
* namespace which would be converted to a standardized message in the front controller.
*
* @author Mathieu Dumoulin aka CrazyCodr <thecrazycodr@gmail.com>
* @license MIT
*/
class FoundTooManyException extends DataException
{
public function __construct(
$message = 'Found too many items in the data source.',
$code = 0,
$previous = null
) {
parent::__construct($message, $code, $previous);
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Data exceptions pertain to all the validation aspect of data and the operations
- FormatException
- IntegrityException
- NotFoundException
- TooManyFoundException
- TypeException
- ValidationException

Expand Down
1 change: 1 addition & 0 deletions Tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function providesConstructorTestClasses()
[\Exceptions\Data\FormatException::class],
[\Exceptions\Data\IntegrityException::class],
[\Exceptions\Data\NotFoundException::class],
[\Exceptions\Data\FoundTooManyException::class],
[\Exceptions\Data\TypeException::class],
[\Exceptions\Data\ValidationException::class],
[\Exceptions\Http\Client\BadRequestException::class],
Expand Down