Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: status code 200-399 indicates success #10

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ You can find more examples on how to use rxjs-probe in [rxjs-probe-examples GitH
## 🔎 Probe Performers

- [Probe Performer](https://github.com/a179346/rxjs-probe-examples/tree/main?tab=readme-ov-file#-custom-probe-performer) - The customizable health check performer
- [Http Probe Performer](https://github.com/a179346/rxjs-probe/tree/main/packages/http-probe-performer#readme) - send HTTP GET requests to perform the health check.
- [Http Probe Performer](https://github.com/a179346/rxjs-probe/tree/main/packages/http-probe-performer#readme) - Sending HTTP GET requests to perform the health check.

## 🤝 Contributing

Expand Down
2 changes: 1 addition & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ You can find more examples on how to use rxjs-probe in [rxjs-probe-examples GitH
## 🔎 Probe Performers

- [Probe Performer](https://github.com/a179346/rxjs-probe-examples/tree/main?tab=readme-ov-file#-custom-probe-performer) - The customizable health check performer
- [Http Probe Performer](https://github.com/a179346/rxjs-probe/tree/main/packages/http-probe-performer#readme) - send HTTP GET requests to perform the health check.
- [Http Probe Performer](https://github.com/a179346/rxjs-probe/tree/main/packages/http-probe-performer#readme) - Sending HTTP GET requests to perform the health check.

## 🤝 Contributing

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { forkJoin, Observable, race, repeat, switchMap, tap, timer } from 'rxjs'
* Use this class to create a custom health check performer.
*
* Or leverage our predefined health check performers:
* - [HttpProbePerformer](https://www.npmjs.com/package/@rxjs-probe/http-probe-performer)
* - [HttpProbePerformer](https://github.com/a179346/rxjs-probe/tree/main/packages/http-probe-performer)
*/
export class ProbePerformer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('HTTP Probe Performer', () => {
expect(healthy).toEqual(true);
}, 2000);

it('should return false when the status code is greater than 399', async () => {
const performer = new HttpProbePerformer({
host: 'localhost',
port: 3000,
path: '/not-found',
});

const observable = performer.createObservable(2);
const healthy = await firstValueFrom(observable);
expect(healthy).toEqual(false);
}, 2000);

it('should return false when timeoutd', async () => {
const performer = new HttpProbePerformer({
host: 'localhost',
Expand Down
4 changes: 4 additions & 0 deletions packages/http-probe-performer/__tests__/test-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
}, responseTimeout);
});

app.get('/not-found', (req, res) => {
res.status(404).send();
});

server = app.listen(3000, () => {
resolve();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/http-probe-performer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class HttpProbePerformer extends ProbePerformer {
credentials: 'same-origin',
});

if (response.status < 200 || response.status >= 300) {
if (response.status < 200 || response.status >= 400) {
throw new Error(`HTTP status code: ${response.status}`);
}
});
Expand Down