Use when reviewing changes to HTTP handlers under src/api/ to check that error responses go through apiError() with a status and code from the team's tables.
84%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
A code convention review lens for Tessl code review. This lens covers error
handling within the API section of a TypeScript project where the API is under
src/api and error handling use a common error handling function apiError
which accepts the HTTP response object, an HTTP status code, and a structure
error code.
Each instance of error handling code that reports an error to the user,
whether logically reachable or not, must use apiError. Not using apiError
will cause API clients to fail hard with no change to recover from the error.
This is a critical failure that must be fixed.
Every use of apiError must use a valid HTTP status code from the HTTP Status
Table.
Every use of apiError must use a structured error code found under "Error
code table"
The chosen HTTP status code and error code must be consistent, e.g. do not
return 418 ("I am a teapot") with error code order_not_found.
apiError is a critical, MUST FIX error. Clients will fail hard
if passed an unstructured error causing the whole system to fail.503 vs. 500) is a
minor finding when the choice is defensible, or a major finding when the
code does not apply to the error (e.g. 503 instead of 404).500 for a 503) is a major
finding, but not a MUST FIX422
instead of 400, 502 instead of 500) is a minor finding.apiError.| Status Code | When |
|---|---|
| 400 | The request has an invalidate structure |
| 401 | Authentication fails |
| 403 | User is not authorized to make the request |
| 404 | The requested resources does not exixt |
| 405 | A resource exists, the user can access it, but they specific HTTP verb is not allowed |
| 415 | A resources exists and is authorized, but not for the content type requested |
| 418 | The applications is a teapot |
| 503 | The applicaiton could not access a downstream service required to respond |
| 500 | Any other error |
| Error Code | When |
|---|---|
| order_not_found | Order cannot be found |
| order_access_denied | Access to the given order is not allowed |
| cannot_update_order | The user can access but not update the order |
| invoice_not_found | Invoice cannot be found |
| invoice_access_denied | Access to the given invoice is not allowed |
| cannot_update_invoice | The user can access but not update the invoice |
| cannot_provide_format | The system is unable to provide the expected response format |
| database_unavailable | Cannot access the database |
| system_is_a_teapot | The system is, in fact, a teapot |
if (!invoice) return apiError(res, 404, 'invoice_not_found');if (!allowed) return apiError(res, 403, 'order_access_denied');if (!allowed) {
return res.status(403).send('access denied');
}if (!database_reached) return apiError(res, 500, 'database_unavailable')if (!order) return apiError(res, 404, 'system_is_a_teapot')crdant/review-lab
ae34af2
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.