More work on the API utilizing Laravel 5.5 exception rendering

Also corrects API format to maintain JSONAPI spec
This commit is contained in:
Dane Everitt 2017-12-17 14:57:05 -06:00
parent f30f4b45ba
commit 54b6fb5ebd
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
28 changed files with 464 additions and 391 deletions

View file

@ -1,20 +1,21 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Exceptions\Model;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Validation\ValidationException;
use Pterodactyl\Exceptions\PterodactylException;
use Illuminate\Contracts\Support\MessageProvider;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class DataValidationException extends ValidationException implements MessageProvider
class DataValidationException extends PterodactylException implements HttpExceptionInterface, MessageProvider
{
/**
* The validator instance.
*
* @var \Illuminate\Contracts\Validation\Validator
*/
public $validator;
/**
* DataValidationException constructor.
*
@ -22,14 +23,38 @@ class DataValidationException extends ValidationException implements MessageProv
*/
public function __construct(Validator $validator)
{
parent::__construct($validator);
parent::__construct(
'Data integrity exception encountered while performing database write operation. ' . $validator->errors()->toJson()
);
$this->validator = $validator;
}
/**
* Return the validator message bag.
*
* @return \Illuminate\Support\MessageBag
*/
public function getMessageBag()
{
return $this->validator->errors();
}
/**
* Return the status code for this request.
*
* @return int
*/
public function getStatusCode()
{
return 500;
}
/**
* @return array
*/
public function getHeaders()
{
return [];
}
}