Skip to main content

Error Handling

Any non-2xx response from the AgentMail API throws an AgentmailException.

Exception properties

MemberTypeDescription
$errorNamestringMachine-readable error name from the API (e.g. "NotFoundError")
getMessage()stringHuman-readable error description from the API
getCode()intHTTP status code (e.g. 404, 422)

Example

use Polkachu\LaravelAgentmail\Exceptions\AgentmailException;
use Polkachu\LaravelAgentmail\Facades\Agentmail;

try {
$inbox = Agentmail::inboxes()->get('inbox_does_not_exist');
} catch (AgentmailException $e) {
echo $e->errorName; // "NotFoundError"
echo $e->getMessage(); // "Inbox not found."
echo $e->getCode(); // 404
}

Common error names

Error nameHTTP statusCause
UnauthorizedError401Missing or invalid API key
NotFoundError404Inbox ID does not exist
ValidationError422Invalid request body (e.g. bad username format)
InternalServerError500Unexpected server-side error