Skip to content

feat(api): add error_type field and HTTP status codes for errors#19

Merged
guanbinrui merged 1 commit intomasterfrom
feat/structured-error-handling
Feb 28, 2026
Merged

feat(api): add error_type field and HTTP status codes for errors#19
guanbinrui merged 1 commit intomasterfrom
feat/structured-error-handling

Conversation

@swkatmask
Copy link

Summary

  • Add optional error_type parameter to respJsonError template for reliable client-side error detection
  • Add httpCode parameter to return proper HTTP status codes
  • Use HTTP 404 for not_found errors (tweet/user not found)

Changes

Before

HTTP/1.1 200 OK
{"code": -1, "error": "Tweet not found"}

After

HTTP/1.1 404 Not Found
{"code": -1, "error": "Tweet not found", "error_type": "not_found"}

Benefits

Clients can now detect not-found errors by:

  1. HTTP status code (response.status === 404)
  2. JSON field (response.error_type === 'not_found')

This is more reliable than parsing error message strings.

Related

- Add optional error_type parameter to respJsonError template for reliable
  client-side error detection
- Add httpCode parameter to return proper HTTP status codes
- Use HTTP 404 for not_found errors (tweet/user not found)
- Use "not_found" error_type for tweet and user not found errors

This allows clients to:
1. Check error_type === 'not_found' instead of parsing error messages
2. Rely on HTTP status codes for proper REST semantics

Example error response:
HTTP/1.1 404 Not Found
{
  "code": -1,
  "error": "Tweet not found",
  "error_type": "not_found"
}
@swkatmask swkatmask force-pushed the feat/structured-error-handling branch from 5b0830a to 35b16ef Compare February 28, 2026 04:15
@guanbinrui guanbinrui merged commit bbef8df into master Feb 28, 2026
0 of 7 checks passed
@guanbinrui guanbinrui deleted the feat/structured-error-handling branch February 28, 2026 04:44
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.

2 participants