Add BaseGraphqlService, support [github] V4 API (#3763)

* add base class for Graphql APIs
* add GithubAuthV4Service + updates to GH token pool
* update github forks to use GithubAuthV4Service
* rename GithubAuthService to GithubAuthV3Service
This commit is contained in:
chris48s
2019-07-29 21:42:03 +01:00
committed by GitHub
parent 320de79309
commit 75ee413178
36 changed files with 756 additions and 120 deletions

28
core/base-service/json.js Normal file
View File

@@ -0,0 +1,28 @@
'use strict'
// See available emoji at http://emoji.muan.co/
const emojic = require('emojic')
const { InvalidResponse } = require('./errors')
const trace = require('./trace')
function parseJson(buffer) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
let json
try {
json = JSON.parse(buffer)
} catch (err) {
logTrace(emojic.dart, 'Response JSON (unparseable)', buffer)
throw new InvalidResponse({
prettyMessage: 'unparseable json response',
underlyingError: err,
})
}
logTrace(emojic.dart, 'Response JSON (before validation)', json, {
deep: true,
})
return json
}
module.exports = {
parseJson,
}