Wordapp API has four kinds of error messages, such as Unauthorized (401)Forbidden (403)Unprocessable entity (422) and Server Error (500). We produce different messages for each status, except 500, in JSON format. When it comes to server error (500) we only send the status code.


Message Types

Unauthorized (401)

This occurs when a user is unauthorized or signed out, or when the access token is expired. When the user is unauthorized, an output including a message is returned from the server such as following.


Sample 401 Output
{
 "status": 401,
 "errors": [
     {
       "auth": "Authentication credentials are invalid."
     }
 ],
 "data": {
     "errors": [
         {
           "auth": "Authentication credentials are invalid."
         }
     ]
 }
}


Forbidden (403)

This happens when a user is authenticated but he is trying to fetch forbidden data such as another user's detail. 

Sample 403 Output
{
  "status": 403,
  "errors": [
    {
      "auth": "You're forbidden to access this resource."
    }
  ],
  "data": {
    "errors": [
      {
        "auth": "You're forbidden to access this resource."
      }
    ]
  }
}


Unprocessable Entity (422)

This happens when a form is submitted without valid data. For example, a user may try to change his e-mail and when he gives corrupt or taken e-mail; a message is sent by server including validation error messages with 422 status code.


Sample 422 Output
{
  "status": 422,
  "errors": [
    {
      "email": [
        "is invalid"
      ],
      "current_password": [
        "You entered your password incorrectly"
      ]
    }
  ],
  "data": {
    "errors": [
      {
        "email": [
          "is invalid"
        ],
        "current_password": [
          "You entered your password incorrectly"
        ]
      }
    ]
  }
}

Server Error (500)