Skip to content

Commit

Permalink
Merge pull request #44 from mehrancodes/handle-configuration-error-me…
Browse files Browse the repository at this point in the history
…ssages

fix: Ensure we show the missing/wrong config error messages properly
  • Loading branch information
mehrancodes authored Nov 6, 2023
2 parents b353d36 + 683dff1 commit 4722804
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public function register(): void
{
$this->reportable(function (ValidationException $e) {
foreach ($e->errors() as $error) {

$this->fail('---> '.current($error));
$this->fail(
sprintf('---> %s', is_array($error) ? current($error) : $error)
);
}

return false;
Expand Down
12 changes: 5 additions & 7 deletions app/Services/Forge/ForgeSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

namespace App\Services\Forge;

use App\Traits\Outputifier;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Laravel\Forge\Exceptions\ValidationException;

class ForgeSetting
{
use Outputifier;

/**
* Forge API authentication token.
*/
Expand Down Expand Up @@ -169,12 +172,7 @@ private function init(array $configurations): void
{
$validator = Validator::make($configurations, $this->validationRules);

if ($validator->fails()) {
// Handle validation failures.
throw new InvalidArgumentException(
'Invalid configuration values: '.implode(', ', $validator->errors()->all())
);
}
throw_if($validator->fails(), ValidationException::class, $validator->errors()->all());

// If validation passes, set properties
foreach ($configurations as $key => $value) {
Expand Down

0 comments on commit 4722804

Please sign in to comment.