1.1 KiB
1.1 KiB
name, description
| name | description |
|---|---|
| dyolink-api-errors | 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
- Add to
ErrorCodeinbackend/src/common/errors/error-codes.ts. - Throw with
AppException:
throw new AppException(ErrorCode.MY_CODE, HttpStatus.BAD_REQUEST, [
{ field: 'email', code: ErrorCode.VALIDATION_EMAIL_INVALID },
]);
- DTOs:
@IsEmail({}, { message: ErrorCode.VALIDATION_EMAIL_INVALID })
Frontend
- Add key under
"errors"inen.json,fa.json,nl.json(key = error code string). - In components:
const tErrors = useTranslations('errors');
// ...
catch (err: unknown) {
toast.showError(getUserFacingError(err, tErrors, t('fallbackKey')));
}
- Do not use
err.messageor(err as Error).messagefor user display.
Axios shape
Parsed in lib/api/client — expects { success: false, error: { code, details? } }.
See rule: .cursor/rules/api-errors-i18n.mdc