{"record":{"id":"d7f8408bb8caeb1c","repo":"mastra-ai/mastra","slug":"registration-failed-with-status-response-status","errorCode":null,"errorMessage":"Registration failed with status ${response.status}: ${response.statusText}","messagePattern":"Registration failed with status (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp-docs-server/src/tools/course.ts","lineNumber":178,"sourceCode":"    req.on('error', error => {\n      reject(error);\n    });\n    req.write(data);\n    req.end();\n  });\n}\n\nasync function registerUser(email: string): Promise<{ success: boolean; id: string; key: string; message: string }> {\n  const response = await fetch('https://mastra.ai/api/course/register', {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({ email }),\n  });\n\n  if (!response.ok) {\n    throw new Error(`Registration failed with status ${response.status}: ${response.statusText}`);\n  }\n\n  return response.json() as Promise<{ success: boolean; id: string; key: string; message: string }>;\n}\n\nasync function readCourseStep(lessonName: string, stepName: string, _isFirstStep: boolean = false): Promise<string> {\n  // Find the lesson directory that matches the name\n  const lessonDirs = await fs.readdir(courseDir);\n  const lessonDir = lessonDirs.find(dir => dir.replace(/^\\d+-/, '') === lessonName);\n\n  if (!lessonDir) {\n    throw new Error(`Lesson \"${lessonName}\" not found.`);\n  }\n\n  // Find the step file that matches the name\n  const lessonPath = path.join(courseDir, lessonDir);\n  const files = await fs.readdir(lessonPath);\n  const stepFile = files.find(f => f.endsWith('.md') && f.replace(/^\\d+-/, '').replace('.md', '') === stepName);","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp-docs-server/src/tools/course.ts#L160-L196","documentation":"registerUser in packages/mcp-docs-server/src/tools/course.ts POSTs an email to the Mastra course registration API and throws `Registration failed with status ${status}: ${statusText}` when the HTTP response is not ok (response.ok false). The error surfaces non-2xx outcomes of the remote registration endpoint (rate limits, invalid email, server outages).","triggerScenarios":"Calling the course registration tool with an email when the remote endpoint returns 4xx/5xx — e.g. invalid email rejected, rate limiting (429), auth failure, or upstream 5xx.","commonSituations":"Typos or malformed emails; registering repeatedly and hitting rate limits; course API downtime or endpoint changes after a version update; corporate proxy/firewall blocking the request and the proxy returning an error status.","solutions":["Read the status/statusText in the error: 4xx usually means fix the input (valid email), 429 means wait and retry, 5xx means retry later","Verify the email address is valid and not already registered","Retry with backoff for 429/5xx responses","Check network/proxy connectivity to the course API endpoint"],"exampleFix":"// before\nawait registerUser({ email: 'not-an-email' }); // 400 -> Registration failed with status 400: Bad Request\n// after\nconst email = 'dev@example.com';\nif (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email)) {\n  throw new Error('Please provide a valid email address');\n}\nawait registerUser({ email });","handlingStrategy":"retry","validationCode":"const email = 'dev@example.com';\nif (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email)) {\n  throw new Error('Invalid email: ' + email);\n}","typeGuard":"null","tryCatchPattern":"try {\n  await registerUser({ email });\n} catch (e) {\n  const m = String(e.message).match(/status (\\d+)/);\n  const status = m ? Number(m[1]) : 0;\n  if (status === 429 || status >= 500) {\n    // retry with backoff\n  } else if (status >= 400) {\n    console.error('Registration rejected — check the email address');\n  } else throw e;\n}","preventionTips":["Validate email format client-side before calling the tool","Implement exponential backoff for 429/5xx statuses","Surface the status code in your own error handling to choose fix-vs-retry","Monitor the course API endpoint for outages/changes before releasing dependent features"],"tags":["http","network","api-error","registration"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}