This tutorial has a new version, check it out!

Symfony RESTful API: Errors (Course 2)


What you'll be learning

In course 1, we added our basic endpoints with some nice tests (yes!).

Now, we turn to a huge part of APIs: handling and returning consistent errors. Seriously, this is more important than you might think - which is why we're covering this in episode 2.

So, let's handle errors, and let's do it gracefully:

  • Handling Form Validation errors and response
  • Disabling csrf_protection
  • Introducing the api-problem JSON format
  • Exception Listener!
  • Consistent errors everywhere: 404's, 500's, oh my!
  • Handling "extra fields" in your form

Your Guides

Ryan Weaver Leanna Pelham

Buy Access

Questions? Conversation?

  • 2019-11-18 weaverryan

    Hey Rosemary!

    No this course specifically, unfortunately. For Symfony 5, we'll likely be focusing more on API Platform - - because it's just SO useful for handling SO many things for you. However, I also want people to be able to learn the fundamentals and create API endpoints without API Platform. Have you tried API Platform? If yes (or no), what are the things that you are especially looking for in this tutorial that you would like to see in Symfony 5? Feedback always motivates what we do :).


  • 2019-11-18 Rosemary

    Will you be updating this course for Symfony 5?

  • 2018-02-21 Diego Aguiar

    Ohh, you are totally right Hugo, sorry for misleading you. If you want to use Guzzle 6 for this course I believe it won't be that hard to tweak the code so it works properly

    Have a nice day

  • 2018-02-21 Hugo do Carmo

    Hi Diego Aguiar, although it's not declared as a dependency, the Guzzle client is used to test the programmer controller, as you can see in ApiTestCase, ResponseAsserter and ProgrammerControllerTest.

    Since it's not declared as a dependency, the developer have the freedom to choose the most recent version, which is incompatible with the current code in this case.


  • 2018-02-20 Diego Aguiar

    Hey Hugo do Carmo

    We don't use Guzzle for this specific course, but thanks for the info anyways!

    Have a nice day

  • 2018-02-20 Hugo do Carmo

    Just a reminder, if you pretend to use Guzzle 6, it now throws exception for 400 and 500 level of errors (see )

    * @return GuzzleHttp\Psr7\Response
    protected function request($uri, array $options, $method = 'GET')
    $response = new Response();

    try {
    $response = $this->client->request($method, $uri, $options);
    } catch(ClientException $e) { /* 400 errors */
    $response = $e->getResponse();
    } catch(ServerException $e) { /* 500 errors */
    $response = $e->getResponse();

    return $response;
  • 2016-05-18 weaverryan

    No worries Vlad :)

  • 2016-05-16 Vlad

    Sorry, disregard! My fault. Please delete.

  • 2016-05-16 Vlad

    Returns the following:


    "type": "validation_error",

    "title": "There was a validation error",

    "errors": [

    "The CSRF token is invalid. Please try to resubmit the form.",

    "Please enter a clever nickname"



    without the 'nickname' subelement.

  • 2016-05-16 Vlad


  • 2015-07-08 weaverryan

    We definitely are - we'll have more this week and yet more next week :)

  • 2015-07-08 Simone Biffi

    Hey guys,
    but this course will not keep more?

  • 2015-06-15 Danny

    Nice. Looking forward to it!

  • 2015-06-15 weaverryan

    Yo Danny! With any luck, we'll start releasing things next week - and we'll finish by the end of June :).


  • 2015-06-12 Danny

    Hey guys,

    When can be expect this to start? :)