debut Exception
This commit is contained in:
@@ -37,6 +37,10 @@ and notification, where you write the content.
|
||||
|
||||
- Open SendPushCommand.php, go to configure(), and change the last line of addOption() for files with your filename.
|
||||
|
||||
## Stacktrace exception API
|
||||
All exceptions catched are written in the dev.log file (for ENV=dev I guess) in the AppBundle/var/logs folder.
|
||||
To have an exception that can be written in this file, create or use an already existing Exception (in AppBundle/Exception) in your Controller.
|
||||
|
||||
## Question to ask to Corentin
|
||||
* Is there a validation from Talents Tube operator to set the answer status to published?
|
||||
* Is there a comment to be written when post an answer ? (not here in mock-up)
|
||||
@@ -236,6 +236,8 @@ monolog:
|
||||
path: '%kernel.logs_dir%/%kernel.environment%_debug.log'
|
||||
|
||||
#Api
|
||||
|
||||
|
||||
fos_rest:
|
||||
zone:
|
||||
- { path: ^/api/* }
|
||||
@@ -252,12 +254,12 @@ fos_rest:
|
||||
rules:
|
||||
- { path: '^/api/', priorities: ['json'], fallback_format: 'json' }
|
||||
param_fetcher_listener: true
|
||||
# exception:
|
||||
# enabled: true
|
||||
# codes:
|
||||
# 'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
|
||||
# messages:
|
||||
# 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage': true
|
||||
exception:
|
||||
enabled: true
|
||||
codes:
|
||||
{ 'AppBundle\Exception\ResourceValidationException': 400 }
|
||||
messages:
|
||||
{ 'AppBundle\Exception\ResourceValidationException': true }
|
||||
|
||||
lexik_jwt_authentication:
|
||||
secret_key: '%kernel.root_dir%/../app/config/jwt/private.pem' # required for token creation
|
||||
|
||||
@@ -20,6 +20,8 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use JMS\Serializer\SerializationContext;
|
||||
use AppBundle\Exception\ResourceValidationException;
|
||||
use AppBundle\Exception\UnknownUserException;
|
||||
|
||||
class AnswerController extends FOSRestController
|
||||
{
|
||||
@@ -84,7 +86,11 @@ class AnswerController extends FOSRestController
|
||||
$companyId = $request->get('companyId');
|
||||
$adId = $request->get('adId');
|
||||
if (!isset($mediaId) || !isset($companyId) || $mediaId == null || $companyId == null){
|
||||
$status = array('status' => "failure", 'message' => "Certaines informations sont vides."); }
|
||||
$message = 'Aucune vidéo ou entreprise sélectionnée.';
|
||||
$status = 'failure';
|
||||
throw new ResourceValidationException($message,$status);
|
||||
}
|
||||
|
||||
else {
|
||||
$video = $em->getRepository('AppBundle:Media')->find($mediaId);
|
||||
$company = $em->getRepository('AppBundle:Company')->find($companyId);
|
||||
@@ -110,7 +116,8 @@ class AnswerController extends FOSRestController
|
||||
}
|
||||
}
|
||||
else {
|
||||
$status = array('status' => "failure", 'message' => "Vous n'êtes pas connecté.");
|
||||
$message = 'Vous n\'êtes pas connecté en tant qu\'utilisateur.';
|
||||
throw new UnknownUserException($message);
|
||||
}
|
||||
return new JsonResponse($status);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use FOS\UserBundle\FOSUserEvents;
|
||||
use FOS\UserBundle\Event\GetResponseUserEvent;
|
||||
use FOS\UserBundle\Model\UserInterface;
|
||||
use AppBundle\Entity\Company;
|
||||
use AppBundle\Exception\ResourceValidationException;
|
||||
|
||||
class SecurityController extends FOSRestController
|
||||
{
|
||||
@@ -112,7 +113,8 @@ class SecurityController extends FOSRestController
|
||||
$newLastName = $request->request->get('lastname');
|
||||
$newFirstName = $request->request->get('firstname');
|
||||
if (!isset($newLastName) || !isset($newFirstName) || $newLastName == null || $newFirstName == null){
|
||||
$status = array('status' => "failure", 'message' => " Les champs Nom et Prénom sont obligatoires.");
|
||||
$message = 'Vous devez rentrer votre nom et votre prénom pour continuer';
|
||||
throw new ResourceValidationException($message);
|
||||
} else {
|
||||
$file = $request->files->get('file');
|
||||
$usr->setLastName($newLastName);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Exception;
|
||||
|
||||
class ResourceValidationException extends \Exception
|
||||
{
|
||||
public $status;
|
||||
protected $message;
|
||||
|
||||
public function __construct($message, $status){
|
||||
$this->message = $message;
|
||||
$this->status = $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Exception;
|
||||
|
||||
class UnknownUserException extends \Exception
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user