bypass checkErrorResponse on [website] badge (#5347)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('@hapi/joi')
|
||||
const emojic = require('emojic')
|
||||
const { optionalUrl } = require('../validators')
|
||||
const {
|
||||
queryParamSchema,
|
||||
@@ -8,6 +9,7 @@ const {
|
||||
renderWebsiteStatus,
|
||||
} = require('../website-status')
|
||||
const { BaseService } = require('..')
|
||||
const trace = require('../../core/base-service/trace')
|
||||
|
||||
const documentation = `
|
||||
<p>
|
||||
@@ -67,6 +69,15 @@ module.exports = class Website extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
async _request({ url, options = {} }) {
|
||||
const logTrace = (...args) => trace.logTrace('fetch', ...args)
|
||||
logTrace(emojic.bowAndArrow, 'Request', url, '\n', options)
|
||||
const { res, buffer } = await this._requestFetcher(url, options)
|
||||
await this._meterResponse(res, buffer)
|
||||
logTrace(emojic.dart, 'Response status code', res.statusCode)
|
||||
return { res, buffer }
|
||||
}
|
||||
|
||||
async handle(
|
||||
_routeParams,
|
||||
{
|
||||
|
||||
@@ -22,6 +22,31 @@ t.create('status when network is off')
|
||||
.networkOff()
|
||||
.expectBadge({ label: 'website', message: 'down', color: 'red' })
|
||||
|
||||
t.create('status is up if response code is 201')
|
||||
.get('/website.json?url=http://online.com')
|
||||
.intercept(nock => nock('http://online.com').head('/').reply(201))
|
||||
.expectBadge({ label: 'website', message: 'up' })
|
||||
|
||||
t.create('status is up if response code is 299')
|
||||
.get('/website.json?url=http://online.com')
|
||||
.intercept(nock => nock('http://online.com').head('/').reply(299))
|
||||
.expectBadge({ label: 'website', message: 'up' })
|
||||
|
||||
t.create('status is up if response code is 301')
|
||||
.get('/website.json?url=http://online.com')
|
||||
.intercept(nock => nock('http://online.com').head('/').reply(301))
|
||||
.expectBadge({ label: 'website', message: 'up' })
|
||||
|
||||
t.create('status is up if response code is 309')
|
||||
.get('/website.json?url=http://online.com')
|
||||
.intercept(nock => nock('http://online.com').head('/').reply(309))
|
||||
.expectBadge({ label: 'website', message: 'up' })
|
||||
|
||||
t.create('status is down if response code is 401')
|
||||
.get('/website.json?url=http://offline.com')
|
||||
.intercept(nock => nock('http://offline.com').head('/').reply(401))
|
||||
.expectBadge({ label: 'website', message: 'down' })
|
||||
|
||||
t.create('custom online label, online message and online color')
|
||||
.get(
|
||||
'/website.json?url=http://online.com&up_message=up&down_message=down&up_color=green&down_color=grey'
|
||||
|
||||
Reference in New Issue
Block a user