improvement: some files replaced, lots of them i shall say. AGENT.MD file created. some rules and skills added for cursor agent.
This commit is contained in:
40
.cursor/skills/api-errors/SKILL.md
Normal file
40
.cursor/skills/api-errors/SKILL.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: dyolink-api-errors
|
||||
description: Adds or migrates Dyolink API error codes with frontend translations. Use when adding backend validation errors, permission errors, or migrating catch blocks to getUserFacingError.
|
||||
---
|
||||
|
||||
# Dyolink API errors
|
||||
|
||||
## Backend
|
||||
|
||||
1. Add to `ErrorCode` in `backend/src/common/errors/error-codes.ts`.
|
||||
2. Throw with `AppException`:
|
||||
|
||||
```typescript
|
||||
throw new AppException(ErrorCode.MY_CODE, HttpStatus.BAD_REQUEST, [
|
||||
{ field: 'email', code: ErrorCode.VALIDATION_EMAIL_INVALID },
|
||||
]);
|
||||
```
|
||||
|
||||
3. DTOs: `@IsEmail({}, { message: ErrorCode.VALIDATION_EMAIL_INVALID })`
|
||||
|
||||
## Frontend
|
||||
|
||||
1. Add key under `"errors"` in `en.json`, `fa.json`, `nl.json` (key = error code string).
|
||||
2. In components:
|
||||
|
||||
```typescript
|
||||
const tErrors = useTranslations('errors');
|
||||
// ...
|
||||
catch (err: unknown) {
|
||||
toast.showError(getUserFacingError(err, tErrors, t('fallbackKey')));
|
||||
}
|
||||
```
|
||||
|
||||
3. Do not use `err.message` or `(err as Error).message` for user display.
|
||||
|
||||
## Axios shape
|
||||
|
||||
Parsed in `lib/api/client` — expects `{ success: false, error: { code, details? } }`.
|
||||
|
||||
See rule: `.cursor/rules/api-errors-i18n.mdc`
|
||||
Reference in New Issue
Block a user