mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-10 03:28:14 +00:00
fix(onboarding): fail fast with a clear error when EXA_API_KEY is missing
The route previously fell back to "x-api-key": process.env.EXA_API_KEY ?? "", so a missing env var produced an outbound call to Exa with an empty key. Exa returned an auth failure, which was then surfaced to the client as a generic 500 "Failed to fetch content from Exa API" — making missing configuration indistinguishable from upstream errors and slowing self-hosted setup. Read EXA_API_KEY once at the top of the handler, log a specific message when it's absent, and return a 500 with a clear "service is not configured" error. The downstream fetch now uses the validated, non-empty key directly.
This commit is contained in:
parent
a8d36df38e
commit
cba67a55ed
1 changed files with 10 additions and 1 deletions
|
|
@ -11,6 +11,15 @@ interface ExaApiResponse {
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
|
const exaApiKey = process.env.EXA_API_KEY
|
||||||
|
if (!exaApiKey) {
|
||||||
|
console.error("EXA_API_KEY is not configured")
|
||||||
|
return Response.json(
|
||||||
|
{ error: "Content extraction service is not configured" },
|
||||||
|
{ status: 500 },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const { urls } = await request.json()
|
const { urls } = await request.json()
|
||||||
|
|
||||||
if (!Array.isArray(urls) || urls.length === 0) {
|
if (!Array.isArray(urls) || urls.length === 0) {
|
||||||
|
|
@ -30,7 +39,7 @@ export async function POST(request: Request) {
|
||||||
const response = await fetch("https://api.exa.ai/contents", {
|
const response = await fetch("https://api.exa.ai/contents", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"x-api-key": process.env.EXA_API_KEY ?? "",
|
"x-api-key": exaApiKey,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue