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:
28
core/base-service/json.js
Normal file
28
core/base-service/json.js
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user