-
Notifications
You must be signed in to change notification settings - Fork 0
fallback
awekrx edited this page May 29, 2026
·
1 revision
import { fallback } from '@dev-suite/decorators/fallback'
method
Return fallback value/handler output when primary call fails.
- Method-level try/catch with default return
- Repeated error fallback blocks
class FeedService {
async list() {
try {
return await this.remote.list();
} catch {
return [];
}
}
}import { fallback } from '@dev-suite/decorators/fallback';
class FeedService {
@fallback({ fallbackValue: [] })
async list() {
return this.remote.list();
}
}- Fallback intent is explicit and reusable.
- Primary path is uncluttered by recovery boilerplate.
class ProfileService {
async getAvatar(userId: string) {
try {
return await this.cdn.avatar(userId);
} catch (error) {
this.logger.warn('avatar fallback', { userId, error });
return this.assets.defaultAvatar;
}
}
}import { fallback } from '@dev-suite/decorators/fallback';
class ProfileService {
@fallback({ onError: () => this.assets.defaultAvatar })
async getAvatar(userId: string) {
return this.cdn.avatar(userId);
}
}- Custom recovery logic moves to config instead of method body.
- Easier to enforce consistent fallback behavior.