Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standardize content-type missing error #145

Merged
merged 9 commits into from
Feb 10, 2023
Merged
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ async function graphqlHandler(event, graphQLOptions) {
'content-type': 'application/json;charset=UTF-8',
}
};
let specialCache = '';
const contentType = request.headers.get('content-type');
if (!contentType || !contentType.startsWith('application/json')) {
specialCache = 'application/json';
}

const requestId = uuidv4();
console.info(requestId);
console.log(new Date().toLocaleString('en-US', { timeZone: 'UTC' }));
console.log(`KVs pre-loaded: ${dataAPI.kvLoaded.join(', ') || 'none'}`);
//console.log(query);
if (request.headers.has('x-newrelic-synthetics')) {
console.log('NewRelic health check');
//return new Response(JSON.stringify({}), responseOptions);
}
let specialCache = '';
const contentType = request.headers.get('content-type');
if (!contentType || !contentType.startsWith('application/json')) {
specialCache = 'application/json';
}

// Check the cache service for data first - If cached data exists, return it
if (!skipCache) {
Expand All @@ -165,8 +169,8 @@ async function graphqlHandler(event, graphQLOptions) {
if (!result.errors) {
result = Object.assign({errors: []}, result);
}
ttl = String(15 * 60);
result.errors.push(`Your request does not have a "content-type" header set to "application/json". Requests missing this header are limited to resposnes that update every ${parseInt(ttl)/60} minutes.`);
ttl = 15 * 60;
result.errors.push({message: `Your request does not have a "content-type" header set to "application/json". Requests missing this header are limited to resposnes that update every ${ttl/60} minutes.`});
}

const body = JSON.stringify(result);
Expand Down