Handling API Errors
Common error codes, what they mean, and how to handle them in your integration.
Enrich Layer uses standard HTTP status codes. Here's how to handle the most common ones.
Error codes
| Status | Meaning | What to do |
|---|---|---|
400 | Bad request — invalid parameters | Check your query parameters. The response body includes details. |
401 | Unauthorized — invalid or missing API key | Verify your API key in the Authorization header. |
403 | Forbidden — insufficient credits or plan limits | Check your credit balance. Upgrade your plan if needed. |
404 | Not found — no profile matched the query | The person or company wasn't found. This is expected for some lookups. |
429 | Rate limited — too many requests | Wait and retry. See Rate Limits. |
500 | Server error — something went wrong on our end | Retry after a few seconds. If persistent, contact support. |
Recommended error handling
async function enrichProfile(url) {
const response = await fetch(
`https://enrichlayer.com/api/v2/profile?profile_url=${encodeURIComponent(url)}`,
{ headers: { Authorization: `Bearer ${API_KEY}` } }
);
if (response.status === 404) {
return null; // Profile not found — expected for some lookups
}
if (response.status === 429) {
// Rate limited — wait and retry
const retryAfter = response.headers.get('Retry-After') || '60';
await new Promise(r => setTimeout(r, parseInt(retryAfter) * 1000));
return enrichProfile(url); // Retry
}
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}javascript
404 is not always an error
A 404 response from a lookup endpoint means the person or company wasn't found in the data source. This is normal — not every profile URL resolves to a profile, and not every email has a matching person.
Handle 404 as a valid "no result" case, not as an error.