# Debug Mode Rules (Non-Obvious Only)

## API Response Codes

- [`request.ts`](src/api/request.ts) returns `response.data` directly, expects `{code: 0, details: ...}`
- [`interceptor.ts`](src/api/interceptor.ts) expects `code: 20000` for success
- Token expiry codes: 50008, 50012, 50014 trigger logout modal (interceptor.ts)
- Token expiry status: 401 or error "Token has expired" (request.ts)

## Token Storage

- Tokens stored via [`SafeStorage`](src/utils/safeStorage.ts) with key `AppStorageKey.TOKEN`.
- Token expiry redirects to `/auth/login` (not `/login`).

## Route Loading Issues

- If routes not loading, check `isMenuLoading`/`isMenuLoaded` flags in [`permission.ts`](src/router/guard/permission.ts).
- Server menu fetched via [`fetchServerMenuConfig()`](src/store/modules/app/index.ts).

## Environment

- Dev config: `.env.development`, Prod config: `.env.production`
- API base URL: `VITE_API_BASE_URL`, Workspace: `VITE_APP_WORKSPACE`

## Common Issues

### useRequest Not Working in Async

- useRequest invokes API immediately - use in setup scope only
- For async contexts, call API directly without useRequest

### Menu Not Loading

- Check console for `[Permission Guard]` logs
- Verify `menuFromServer` setting in app store
- Check `fetchServerMenuConfig()` response

### Token Expiry

- Response `status: 401` or `error: 'Token has expired'` triggers logout
- Clear storage via `SafeStorage.clearAppStorage()`

## Debug Commands

```bash
# Check lint errors
pnpm lint

# Type check
pnpm build

# Dev server with logs
pnpm dev
```

## Browser DevTools

- Vue DevTools for component state
- Network tab for API calls
- Console for `[Permission Guard]` logs
