mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-08-25 08:08:00 +00:00
1ada95e04a
- Convert project to Javascript/Typescript - Allow custom headers to be passed in (optional) - Allow body to be optional
36 lines
589 B
JavaScript
36 lines
589 B
JavaScript
'use strict';
|
|
var errorEx = require('error-ex');
|
|
var fallback = require('./vendor/parse');
|
|
|
|
var JSONError = errorEx('JSONError', {
|
|
fileName: errorEx.append('in %s')
|
|
});
|
|
|
|
module.exports = function (x, reviver, filename) {
|
|
if (typeof reviver === 'string') {
|
|
filename = reviver;
|
|
reviver = null;
|
|
}
|
|
|
|
try {
|
|
try {
|
|
return JSON.parse(x, reviver);
|
|
} catch (err) {
|
|
fallback.parse(x, {
|
|
mode: 'json',
|
|
reviver: reviver
|
|
});
|
|
|
|
throw err;
|
|
}
|
|
} catch (err) {
|
|
var jsonErr = new JSONError(err);
|
|
|
|
if (filename) {
|
|
jsonErr.fileName = filename;
|
|
}
|
|
|
|
throw jsonErr;
|
|
}
|
|
};
|