[appveyor] Error handling in BaseService (#1590)

Make a clear distinction between programmer errors ("internal errors") and runtime errors, and allow configuring the server to let the programmer errors bubble up in development and unit testing. This saves a huge amount of time because it generates ordinary stack traces when things go wrong. And, if these errors occur in production, we'll catch them, and display **shields | internal error** which is the equivalent of a 500 error.
This commit is contained in:
Paul Melnikow
2018-04-01 22:04:22 -05:00
committed by GitHub
parent 724abd06dc
commit 416d433fa0
12 changed files with 216 additions and 38 deletions

View File

@@ -1,26 +1,23 @@
'use strict';
const BaseService = require('../base');
const {
checkErrorResponse,
asJson,
} = require('../../lib/error-helper');
/**
* AppVeyor CI integration.
*/
module.exports = class AppVeyor extends BaseService {
async handle({repo, branch}) {
let apiUrl = 'https://ci.appveyor.com/api/projects/' + repo;
if (branch != null) {
apiUrl += '/branch/' + branch;
}
const {buffer, res} = await this._sendAndCacheRequest(apiUrl, {
const json = await this._sendAndCacheRequest(apiUrl, {
headers: { 'Accept': 'application/json' }
});
}).then(checkErrorResponse.asPromise({ notFoundMessage: 'project not found or access denied' }))
.then(asJson);
if (res.statusCode === 404) {
return {message: 'project not found or access denied'};
}
const data = JSON.parse(buffer);
const status = data.build.status;
const { build: { status } } = json;
if (status === 'success') {
return {message: 'passing', color: 'brightgreen'};
} else if (status !== 'running' && status !== 'queued') {

View File

@@ -25,6 +25,11 @@ t.create('CI 404')
.get('/ci/somerandomproject/thatdoesntexits.json')
.expectJSON({ name: 'build', value: 'project not found or access denied' });
t.create('CI (connection error)')
.get('/ci/this-one/is-not-real-either.json')
.networkOff()
.expectJSON({ name: 'build', value: 'inaccessible' });
// Test AppVeyor tests status badge
t.create('tests status')
.get('/tests/NZSmartie/coap-net-iu0to.json')