Skip to content

Allow custom error formatting

Pre-release
Pre-release
Compare
Choose a tag to compare
@chrissm79 chrissm79 released this 11 Apr 16:04
· 3552 commits to master since this release
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register()
    {
        // ...

       // Register custom error formatting
        \GraphQL::error(function ($error, $e) {
            $previous = $e->getPrevious();

            if ($previous && $previous instanceof \Nuwave\Lighthouse\Support\Exceptions\ValidationError) {
                $error['status_code'] = 422;
            }

            return $error;
        });
    }
}