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:
chris48s
2020-07-26 16:44:31 +01:00
committed by GitHub
parent 23f416b42a
commit f3d17ff435
2 changed files with 36 additions and 0 deletions

View File

@@ -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,
{

View File

@@ -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'