-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement better validation error with fields (#125)
- Loading branch information
Showing
4 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Bakery\Errors; | ||
|
||
use GraphQL\Error\Error; | ||
use GraphQL\Error\ClientAware; | ||
|
||
class ValidationError extends Error implements ClientAware | ||
{ | ||
/** | ||
* The validator instance. | ||
* | ||
* @var \Illuminate\Contracts\Validation\Validator | ||
*/ | ||
public $validator; | ||
|
||
/** | ||
* Create a new exception instance. | ||
* | ||
* @param \Illuminate\Contracts\Validation\Validator $validator | ||
* @return void | ||
*/ | ||
public function __construct($validator) | ||
{ | ||
parent::__construct($validator->errors()->first()); | ||
|
||
$this->validator = $validator; | ||
$this->extensions['validation'] = $validator->errors(); | ||
} | ||
|
||
/** | ||
* Returns true when exception message is safe to be displayed to a client. | ||
* | ||
* @return bool | ||
* @api | ||
*/ | ||
public function isClientSafe() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Returns string describing a category of the error. | ||
* | ||
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. | ||
* | ||
* @return string | ||
* @api | ||
*/ | ||
public function getCategory() | ||
{ | ||
return 'user'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters