Skip to content

Commit

Permalink
feat(ping): support for custom http success codes. Fix #425
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienwirtz committed Nov 18, 2024
1 parent 9b0e3f5 commit 721a8c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/customservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ API key can be generated in Settings > Administration > Auth Tokens

## Ping

This card checks if the target link is available. All you need is to set the `type` to `Ping` and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property. By default, the subtitle line shows the round trip time (RTT) of the request, unless you provide the `subtitle` property.
This card checks if the target link is available. All you need is to set the `type` to `Ping` and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property. By default, the subtitle line shows the round trip time (RTT) of the request, unless you provide the `subtitle` property. Optionnaly, use `successCodes` to define which HTTP response status codes should be considered as available status.

```yaml
- name: "Awesome app"
type: Ping
logo: "assets/tools/sample.png"
url: "https://www.wikipedia.org/"
# method: "head"
# successCodes: [200, 418] # optional, default to all 2xx HTTP response status codes
# timeout: 500 # in ms. default 2000
# subtitle: "Bookmark example" # By default, request round trip time is displayed when subtitle is not set.
```
Expand Down
7 changes: 6 additions & 1 deletion src/mixins/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export default {
}

return fetch(url, options).then((response) => {
if (!response.ok) {
let success = response.ok;
if (Array.isArray(this.item.successCodes)) {
success = this.item.successCodes.includes(response.status);
}

if (!success) {
throw new Error(`Ping: target not available (${response.status} error)`);
}

Expand Down

0 comments on commit 721a8c2

Please sign in to comment.