<?php
$errorTypes = $this->getParam('errors', []);
?>

<p>Appwrite uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, invalid input, etc.). Codes in the 5xx range indicate an error with the Appwrite server, but these are rare.</p>

<table cellspacing="0" cellpadding="0" border="0" class="full vertical text-size-small">
    <thead>
        <tr>
            <th style="width: 100px">Code</th>
            <th style="width: 180px">Text</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td data-title="Code: ">200</td>
            <td data-title="Text: ">OK</td>
            <td data-title="Description: ">Success!</td>
        </tr>

        <tr>
            <td data-title="Code: ">201</td>
            <td data-title="Text: ">Created</td>
            <td data-title="Description: ">The requested resource has been created successfully.</td>
        </tr>

        <tr>
            <td data-title="Code: ">202</td>
            <td data-title="Text: ">Accepted</td>
            <td data-title="Description: ">The requested change has been accepted for processing but has not been completed.</td>
        </tr>

        <tr>
            <td data-title="Code: ">204</td>
            <td data-title="Text: ">No Content</td>
            <td data-title="Description: ">The server has successfully fulfilled the request and that there is no additional content to send in the response payload body. This status will usually return on successful delete operations.</td>
        </tr>

        <tr>
            <td data-title="Code: ">301</td>
            <td data-title="Text: ">Moved Permanently</td>
            <td data-title="Description: ">The URL of the requested resource has been changed permanently. The new URL is given in the response.</td>
        </tr>

        <tr>
            <td data-title="Code: ">304</td>
            <td data-title="Text: ">Not Modified</td>
            <td data-title="Description: ">There was no new data to return.</td>
        </tr>

        <tr>
            <td data-title="Code: ">400</td>
            <td data-title="Text: ">Bad Request</td>
            <td data-title="Description: ">The request was invalid or cannot be otherwise served. An accompanying error message will explain further. Requests with wrong or invalid input will yield this response.</td>
        </tr>

        <tr>
            <td data-title="Code: ">401</td>
            <td data-title="Text: ">Unauthorized</td>
            <td data-title="Description: ">Missing or incorrect authentication credentials can happen when the API key or user permission is not sufficient.</td>
        </tr>

        <tr>
            <td data-title="Code: ">403</td>
            <td data-title="Text: ">Forbidden</td>
            <td data-title="Description: ">The request is understood, but it has been refused, or access is not allowed. An accompanying error message will explain why. Make sure to register your app in your project's dashboard platform list.</td>
        </tr>

        <tr>
            <td data-title="Code: ">404</td>
            <td data-title="Text: ">Not Found</td>
            <td data-title="Description: ">The URI requested is invalid or the resource requested, such as a user, does not exist.</td>
        </tr>

        <tr>
            <td data-title="Code: ">409</td>
            <td data-title="Text: ">Conflict</td>
            <td data-title="Description: ">This response is sent when a request conflicts with the current state of the server. This status code will usually appear when you're trying to create an already existing resource.</td>
        </tr>

        <tr>
            <td data-title="Code: ">413</td>
            <td data-title="Text: ">Payload Too Large</td>
            <td data-title="Description: ">This indicates that the request entity is larger than limits defined by server. This status code will usually appear happen when uploading a file or function that is too large</td>
        </tr>

        <tr>
            <td data-title="Code: ">416</td>
            <td data-title="Text: ">Invalid Range</td>
            <td data-title="Description: ">Invalid value in the range or content-range headers. Usually returned while uploading or downloading files using range header but the provided range value is not valid.</td>
        </tr>

        <tr>
            <td data-title="Code: ">429</td>
            <td data-title="Text: ">Too Many Requests</td>
            <td data-title="Description: ">Returned in when a request cannot be served due to the application's rate limit having been exhausted for the resource. <a href="/docs/rate-limits">See Rate Limits</a></td>
        </tr>

        <tr>
            <td data-title="Code: ">500</td>
            <td data-title="Text: ">Internal Server Error</td>
            <td data-title="Description: ">Something is broken. Contact our <a href="/support">team</a>, or raise a <a href="https://github.com/appwrite/appwrite/issues/new" target="_blank" rel="noopener">GitHub issue</a>.</td>
        </tr>

        <tr>
            <td data-title="Code: ">501</td>
            <td data-title="Text: ">Not Implemented</td>
            <td data-title="Description: ">The feature is not implemented. Usually returned when the project owner has disabled an auth method or an entire service.</td>
        </tr>

        <tr>
            <td data-title="Code: ">503</td>
            <td data-title="Text: ">Service Unavailable</td>
            <td data-title="Description: ">The Appwrite servers are up but overloaded with requests. Try again later.</td>
        </tr>

        <tr>
            <td data-title="Code: ">504</td>
            <td data-title="Text: ">Gateway timeout</td>
            <td data-title="Description: ">The Appwrite servers are up, but the request couldn't be serviced due to some failure within the stack. Try again later.</td>
        </tr>

    </tbody>
</table>

<h2><a href="/docs/response-codes#errorMessages" id="errorMessages">Error Messages</a></h2>

<p>When the Appwrite APIs return error messages, it does so in JSON format. For example, an error might look like this:</p>

<div class="ide">
    <pre class="line-numbers"><code class="prism language-javascript" data-prism>{
    "message": "Invalid id: Parameter must be a valid number",
    "type": "argument_invalid",
    "code": 400
}
</code></pre>
</div>

<h2><a href="/docs/response-codes#errorTypes" id="errorTypes">Error Types</a></h2>

<p> Appwrite also passes convenient error types in addition to the HTTP response codes to help you get more fine grained control over what went wrong and allowing you to display relevant error messages in your applications. Error types are convenient to identify the type of error that occurred. </p>

<p> For eg: A <span class="tag">400</span> HTTP response code could indicate a Bad Request due to a variety of reasons and error types can help you pinpoint the exact <span class="tag">400</span> error. Appwrite currently supports the following error types:</p>

<table cellspacing="0" cellpadding="0" border="0" class="full margin-bottom-large">
    <thead>
        <tr>
            <th style="width: 40px">Code</th>
            <th style="width: 245px">Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
<?php foreach($errorTypes as $type): ?>
        <tr>
            <td><?php echo $type['code']; ?></td>
            <td><?php echo $type['name']; ?></td>
            <td><?php echo $type['description']?></td>
        </tr>
<?php endforeach; ?>
    </tbody>
</table>
