fix: surface DataForSEO auth failures as an actionable error instead of "unexpected error" (#53)
This commit is contained in:
parent
b8f47a51cc
commit
c8a1e17359
@ -22,6 +22,8 @@ const STANDARD_MESSAGES: Record<ErrorCode, string> = {
|
|||||||
"AI Optimization is not enabled for the connected DataForSEO account yet.",
|
"AI Optimization is not enabled for the connected DataForSEO account yet.",
|
||||||
AI_SEARCH_BILLING_ISSUE:
|
AI_SEARCH_BILLING_ISSUE:
|
||||||
"The connected DataForSEO account has a billing or balance 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.",
|
RATE_LIMITED: "Too many requests. Please wait and try again.",
|
||||||
UPSTREAM_UNAVAILABLE:
|
UPSTREAM_UNAVAILABLE:
|
||||||
"The data provider is temporarily unavailable. Please retry in a moment.",
|
"The data provider is temporarily unavailable. Please retry in a moment.",
|
||||||
|
|||||||
@ -96,7 +96,9 @@ function createAuthenticatedFetch(classify?: DataforseoErrorClassifier) {
|
|||||||
? "UPSTREAM_UNAVAILABLE"
|
? "UPSTREAM_UNAVAILABLE"
|
||||||
: response.status === 429
|
: response.status === 429
|
||||||
? "RATE_LIMITED"
|
? "RATE_LIMITED"
|
||||||
: "INTERNAL_ERROR";
|
: response.status === 401
|
||||||
|
? "DATAFORSEO_AUTH_FAILED"
|
||||||
|
: "INTERNAL_ERROR";
|
||||||
const error = new AppError(
|
const error = new AppError(
|
||||||
code,
|
code,
|
||||||
`DataForSEO HTTP ${response.status} on ${path}`,
|
`DataForSEO HTTP ${response.status} on ${path}`,
|
||||||
|
|||||||
@ -58,6 +58,14 @@ export async function fetchDataforseoAccountState(): Promise<DataforseoAccountSt
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
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(
|
throw new AppError(
|
||||||
"INTERNAL_ERROR",
|
"INTERNAL_ERROR",
|
||||||
`DataForSEO HTTP ${response.status} on /v3/appendix/user_data`,
|
`DataForSEO HTTP ${response.status} on /v3/appendix/user_data`,
|
||||||
|
|||||||
@ -14,6 +14,7 @@ const ERROR_CODES = [
|
|||||||
"BACKLINKS_BILLING_ISSUE",
|
"BACKLINKS_BILLING_ISSUE",
|
||||||
"AI_SEARCH_NOT_ENABLED",
|
"AI_SEARCH_NOT_ENABLED",
|
||||||
"AI_SEARCH_BILLING_ISSUE",
|
"AI_SEARCH_BILLING_ISSUE",
|
||||||
|
"DATAFORSEO_AUTH_FAILED",
|
||||||
"RATE_LIMITED",
|
"RATE_LIMITED",
|
||||||
"UPSTREAM_UNAVAILABLE",
|
"UPSTREAM_UNAVAILABLE",
|
||||||
"CONFLICT",
|
"CONFLICT",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user