endpoints-errors-cors-and-responses
Use when: shaping Payload endpoint responses, adding CORS headers, or handling validation and error cases consistently.
Install / Use
npx skills add kiwagu/proflowInstalls into whichever agent you are using.
Cursor Rules
Cursor IDE rules (v2)
Quality Score
Category
Development & EngineeringSupported Platforms
Tags
Skill content
View source on GitHubtitle: Endpoints - Errors, CORS, and Responses description: Use when: shaping Payload endpoint responses, adding CORS headers, or handling validation and error cases consistently. tags: [payload, endpoints, cors, errors, responses]
Payload Endpoints: Errors, CORS, and Responses
Pyramid Layer
- Layer: L3 Payload leaf.
Use This When
- Load this after the endpoints router when the endpoint exists but the response and failure contract still need to be shaped.
Stop Here If
- Stop once the response and error pattern are clear.
Descend To
- Return to
/.cursor/rules/endpoints.mdfor request-handling or placement siblings.
CORS Headers
import { headersWithCors } from 'payload'
export const corsEndpoint: Endpoint = {
path: '/public-data',
method: 'get',
handler: async (req) => {
const data = await fetchPublicData()
return Response.json(data, {
headers: headersWithCors({
headers: new Headers(),
req,
}),
})
},
}
Error Handling
import { APIError } from 'payload'
export const validateEndpoint: Endpoint = {
path: '/validate',
method: 'post',
handler: async (req) => {
const data = await req.json()
if (!data.email) {
throw new APIError('Email is required', 400)
}
return Response.json({ valid: true })
},
}
Response Rules
- Return Web
Responseobjects, preferably withResponse.json(). - Throw
APIErrorfor predictable request failures. - Validate input explicitly.
- Use
req.payload.loggerfor endpoint debugging rather than silent failure.
Related Skills
Agent-Reach
84.5kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
73.4kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
career-ops
72.4kOpen-source AI job search: scan job portals, evaluate listings into a structured A-H report with a global 1-5 score, tailor your CV, track applications — runs locally in your AI coding CLI (Claude Code, Codex, OpenCode, Antigravity…)
ai-job-search
43.6kThe job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.
Security Score
Audited on Invalid Date
