Skip to content

Commit 75ded00

Browse files
committed
added console log of requests when debug=true
1 parent f1f9b53 commit 75ded00

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

package-lock.json

Lines changed: 11 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agility/content-fetch",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"description": "JavaScript library for the Agility Fetch API (node and browser)",
55
"main": "dist/agility-content-fetch.node.js",
66
"scripts": {

src/api-client.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import getGallery from './methods/getGallery'
99
import FilterOperators from './types/FilterOperator'
1010
import FilterLogicOperators from './types/FilterLogicOperator'
1111
import SortDirections from './types/SortDirection'
12-
import { logError } from './utils'
12+
import { logError, logDebug } from './utils'
1313

1414
const defaultConfig = {
1515
baseUrl: null,
@@ -19,6 +19,7 @@ const defaultConfig = {
1919
languageCode: null,
2020
headers: {},
2121
requiresGuidInHeaders: false,
22+
debug: false,
2223
caching: {
2324
maxAge: 0 //caching disabled by default
2425
}
@@ -60,8 +61,14 @@ export default function createClient(userConfig) {
6061

6162
//the function that actually makes ALL our requests
6263
function makeRequest(reqConfig) {
63-
//make the request using our axios instance
64+
65+
if(config.debug) {
66+
logDebug(`AgilityCMS Fetch API LOG: ${reqConfig.baseURL}${reqConfig.url}`);
67+
}
68+
69+
//make the request using our axios instance
6470
return api(reqConfig).then(async (response) => {
71+
6572
let data = response.data;
6673
//if our response is from cache, inject that property in the data response
6774
if(response.request.fromCache) {

src/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ function logError(consoleMessage) {
22
console.error('\x1b[41m%s\x1b[0m', consoleMessage);
33
}
44

5+
function logDebug(consoleMessage) {
6+
console.log('\x1b[33m%s\x1b[0m', consoleMessage);
7+
}
8+
59
function buildRequestUrlPath(config, languageCode) {
610
let apiFetchOrPreview = null;
711

@@ -68,5 +72,6 @@ export {
6872
buildAuthHeader,
6973
buildRequestUrlPath,
7074
isHttps,
71-
logError
75+
logError,
76+
logDebug
7277
}

0 commit comments

Comments
 (0)