Skip to content

Commit d962ddb

Browse files
docs: minor text updates
1 parent d11be73 commit d962ddb

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

content/migration.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ A new `skipProcessEnv` option has also been introduced. This option allows you t
205205

206206
If you are using the `TerminusModule` and have built your own custom health indicator, a new API has been introduced in version 11. The new `HealthIndicatorService` is designed to enhance the readability and testability of custom health indicators.
207207

208-
**Previous Approach**
209-
210208
Before version 11, a health indicator might have looked like this:
211209

212210
```typescript
@@ -216,21 +214,14 @@ export class DogHealthIndicator extends HealthIndicator {
216214
super();
217215
}
218216

219-
private getBadboys() {
220-
return firstValueFrom(
221-
this.httpService.get<Dog[]>('https://example.com/dog').pipe(
222-
map((response) => response.data),
223-
map((dogs) => dogs.filter((dog) => dog.state === DogState.BAD_BOY)),
224-
),
225-
);
226-
}
227-
228217
async isHealthy(key: string) {
229218
try {
230219
const badboys = await this.getBadboys();
231220
const isHealthy = badboys.length === 0;
232221

233-
const result = this.getStatus(key, isHealthy, { badboys: badboys.length });
222+
const result = this.getStatus(key, isHealthy, {
223+
badboys: badboys.length,
224+
});
234225

235226
if (!isHealthy) {
236227
throw new HealthCheckError('Dog check failed', result);
@@ -242,12 +233,19 @@ export class DogHealthIndicator extends HealthIndicator {
242233
throw new HealthCheckError('Dog check failed', result);
243234
}
244235
}
236+
237+
private getBadboys() {
238+
return firstValueFrom(
239+
this.httpService.get<Dog[]>('https://example.com/dog').pipe(
240+
map((response) => response.data),
241+
map((dogs) => dogs.filter((dog) => dog.state === DogState.BAD_BOY)),
242+
),
243+
);
244+
}
245245
}
246246
```
247247

248-
**Updated Approach (NestJS Terminus v11)**
249-
250-
In version 11, it is recommended to use the new `HealthIndicatorService` API, which simplifies the implementation. Here's how the same health indicator can be implemented:
248+
Starting with version 11, it is recommended to use the new `HealthIndicatorService` API, which streamlines the implementation process. Here's how the same health indicator can now be implemented:
251249

252250
```typescript
253251
@Injectable()
@@ -258,8 +256,6 @@ export class DogHealthIndicator {
258256
private readonly healthIndicatorService: HealthIndicatorService,
259257
) {}
260258

261-
private getBadboys() { // ... }
262-
263259
async isHealthy(key: string) {
264260
// Start the health indicator check for the given key
265261
const indicator = this.healthIndicatorService.check(key);
@@ -278,15 +274,19 @@ export class DogHealthIndicator {
278274
return indicator.down('Unable to retrieve dogs');
279275
}
280276
}
277+
278+
private getBadboys() {
279+
// ...
280+
}
281281
}
282282
```
283283

284-
**Key changes**
284+
Key changes:
285285

286-
- The `HealthIndicatorService` replaces the older `HealthIndicator` and `HealthCheckError` classes, providing a cleaner API for health checks.
287-
- The `check` method allows easy state tracking (`up` or `down`) while supporting additional metadata to be included in health check responses.
286+
- The `HealthIndicatorService` replaces the legacy `HealthIndicator` and `HealthCheckError` classes, providing a cleaner API for health checks.
287+
- The `check` method allows for easy state tracking (`up` or `down`) while supporting the inclusion of additional metadata in health check responses.
288288

289-
> info **Info** Please note that the `HealthIndicator` and `HealthCheckError` classes have been marked as deprecated and are scheduled for removal in the next major release.
289+
> info **Info** Please note that the `HealthIndicator` and `HealthCheckError` classes have been marked as deprecated and are scheduled for removal in the next major release.
290290
291291
#### Node.js v16 no longer supported
292292

0 commit comments

Comments
 (0)