fix: surface DataForSEO auth failures as an actionable error instead of "unexpected error" (#53)

This commit is contained in:
mattmacrocket 2026-07-02 16:38:13 -05:00 committed by GitHub
parent b8f47a51cc
commit c8a1e17359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,8 @@ const STANDARD_MESSAGES: Record<ErrorCode, string> = {
"AI Optimization is not enabled for the connected DataForSEO account yet.",
AI_SEARCH_BILLING_ISSUE:
"The connected DataForSEO account has a billing or balance issue.",
DATAFORSEO_AUTH_FAILED:
"DataForSEO rejected the API key. Check that DATAFORSEO_API_KEY is the base64 of your DataForSEO login:password.",
RATE_LIMITED: "Too many requests. Please wait and try again.",
UPSTREAM_UNAVAILABLE:
"The data provider is temporarily unavailable. Please retry in a moment.",

View File

@ -96,7 +96,9 @@ function createAuthenticatedFetch(classify?: DataforseoErrorClassifier) {
? "UPSTREAM_UNAVAILABLE"
: response.status === 429
? "RATE_LIMITED"
: "INTERNAL_ERROR";
: response.status === 401
? "DATAFORSEO_AUTH_FAILED"
: "INTERNAL_ERROR";
const error = new AppError(
code,
`DataForSEO HTTP ${response.status} on ${path}`,

View File

@ -58,6 +58,14 @@ export async function fetchDataforseoAccountState(): Promise<DataforseoAccountSt
});
if (!response.ok) {
// 401/403 here means the API key itself is invalid or missing — surface a
// clear, actionable message instead of a generic "unexpected error".
if (response.status === 401 || response.status === 403) {
throw new AppError(
"DATAFORSEO_AUTH_FAILED",
`DataForSEO HTTP ${response.status} on /v3/appendix/user_data`,
);
}
throw new AppError(
"INTERNAL_ERROR",
`DataForSEO HTTP ${response.status} on /v3/appendix/user_data`,

View File

@ -14,6 +14,7 @@ const ERROR_CODES = [
"BACKLINKS_BILLING_ISSUE",
"AI_SEARCH_NOT_ENABLED",
"AI_SEARCH_BILLING_ISSUE",
"DATAFORSEO_AUTH_FAILED",
"RATE_LIMITED",
"UPSTREAM_UNAVAILABLE",
"CONFLICT",