Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 8, 2025

This PR adds convenient response helper methods to simplify common HTTP status code responses, addressing the boilerplate of manually setting res.statusCode = 400 and similar patterns.

Added Response Helpers

The following methods are now available on the response object:

  • res.badRequest(message?) - Sets 400 Bad Request
  • res.unauthorized(message?) - Sets 401 Unauthorized
  • res.forbidden(message?) - Sets 403 Forbidden
  • res.notFound(message?) - Sets 404 Not Found
  • res.internalServerError(message?) - Sets 500 Internal Server Error

Usage

Each helper can be used with or without an error message:

// Without message (status code only)
export default (req, res) => {
  return res.badRequest()
}

// With message (status code + JSON error response)
export default (req, res) => {
  return res.badRequest('Invalid input data')
  // Sends: {"error": "Invalid input data"} with 400 status
}

Implementation Details

  • When called without a message, only the status code is set and the response ends
  • When called with a message, the response includes Content-Type: application/json and sends {"error": "message"}
  • All helpers automatically call res.end() to complete the response
  • TypeScript definitions are included for full type safety

Testing

Comprehensive tests validate all helpers work correctly with and without messages, ensuring proper status codes, content types, and response bodies.

Fixes #31.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 8, 2025 16:50
Co-authored-by: barelyhuman <43572006+barelyhuman@users.noreply.github.com>
…idden, notFound, internalServerError)

Co-authored-by: barelyhuman <43572006+barelyhuman@users.noreply.github.com>
Copilot AI changed the title [WIP] Response Helpers Add HTTP status code response helpers Jul 8, 2025
Copilot AI requested a review from barelyhuman July 8, 2025 16:55
barelyhuman

This comment was marked as duplicate.

@barelyhuman
Copy link
Owner

I've made a commit removing the package-lock.json files, the workspaces uses pnpm, make a commit so you remember to check and use that the next time an issue is assigned to

@copilot

Co-authored-by: barelyhuman <43572006+barelyhuman@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 8, 2025

I've made a commit removing the package-lock.json files, the workspaces uses pnpm, make a commit so you remember to check and use that the next time an issue is assigned to

@copilot

Understood! I've added package-lock.json to .gitignore since the workspace uses pnpm. Will use pnpm for any future dependency management. Thanks for cleaning up those files! (commit a157aa9)

I've made a commit removing the package-lock.json files, the workspaces uses pnpm, make a commit so you remember to check and use that the next time an issue is assigned to

@copilot

Got it! Added package-lock.json to .gitignore and will use pnpm for future work instead of npm. (commit a157aa9)

Copilot AI requested a review from barelyhuman July 8, 2025 17:02
@barelyhuman barelyhuman marked this pull request as ready for review July 8, 2025 17:03
@barelyhuman barelyhuman merged commit e83ab54 into main Jul 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Response Helpers

2 participants