Skip to content

Commit

Permalink
added console log of requests when debug=true
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesvidler committed Oct 8, 2019
1 parent f1f9b53 commit 75ded00
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agility/content-fetch",
"version": "0.5.7",
"version": "0.5.8",
"description": "JavaScript library for the Agility Fetch API (node and browser)",
"main": "dist/agility-content-fetch.node.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import getGallery from './methods/getGallery'
import FilterOperators from './types/FilterOperator'
import FilterLogicOperators from './types/FilterLogicOperator'
import SortDirections from './types/SortDirection'
import { logError } from './utils'
import { logError, logDebug } from './utils'

const defaultConfig = {
baseUrl: null,
Expand All @@ -19,6 +19,7 @@ const defaultConfig = {
languageCode: null,
headers: {},
requiresGuidInHeaders: false,
debug: false,
caching: {
maxAge: 0 //caching disabled by default
}
Expand Down Expand Up @@ -60,8 +61,14 @@ export default function createClient(userConfig) {

//the function that actually makes ALL our requests
function makeRequest(reqConfig) {
//make the request using our axios instance

if(config.debug) {
logDebug(`AgilityCMS Fetch API LOG: ${reqConfig.baseURL}${reqConfig.url}`);
}

//make the request using our axios instance
return api(reqConfig).then(async (response) => {

let data = response.data;
//if our response is from cache, inject that property in the data response
if(response.request.fromCache) {
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ function logError(consoleMessage) {
console.error('\x1b[41m%s\x1b[0m', consoleMessage);
}

function logDebug(consoleMessage) {
console.log('\x1b[33m%s\x1b[0m', consoleMessage);
}

function buildRequestUrlPath(config, languageCode) {
let apiFetchOrPreview = null;

Expand Down Expand Up @@ -68,5 +72,6 @@ export {
buildAuthHeader,
buildRequestUrlPath,
isHttps,
logError
logError,
logDebug
}

0 comments on commit 75ded00

Please sign in to comment.