Skip to content

Commit

Permalink
Merge pull request #417 from OpenFn/dhis2-rm-class-log
Browse files Browse the repository at this point in the history
`dhis2` remove `Class Log`
  • Loading branch information
josephjclark authored Oct 24, 2023
2 parents 65243bd + 6b89e24 commit bb79e16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .changeset/unlucky-cobras-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@openfn/language-dhis2': patch
---

remove Class Log and replaced

- `Log.success` with `console.log`
- `Log.warn` with `console.warn`
- `Log.error` with `console.error`
21 changes: 10 additions & 11 deletions packages/dhis2/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
CONTENT_TYPES,
generateUrl,
handleResponse,
Log,
nestArray,
prettyJson,
selectId,
Expand Down Expand Up @@ -55,7 +54,7 @@ export function execute(...operations) {
function configMigrationHelper(state) {
const { hostUrl, apiUrl } = state.configuration;
if (!hostUrl) {
Log.warn(
console.warn(
'DEPRECATION WARNING: Please migrate instance address from `apiUrl` to `hostUrl`.'
);
state.configuration.hostUrl = apiUrl;
Expand All @@ -82,7 +81,7 @@ axios.interceptors.response.use(
responseData: response.data,
};

Log.error(newError.message);
console.error(newError.message);

return Promise.reject(newError);
}
Expand All @@ -96,7 +95,7 @@ axios.interceptors.response.use(
// eslint-disable-next-line no-param-reassign
response = { ...response, data: JSON.parse(response.data) };
} catch (error) {
Log.warn('Non-JSON response detected, unable to parse.');
console.warn('Non-JSON response detected, unable to parse.');
}
}
return response;
Expand All @@ -107,7 +106,7 @@ axios.interceptors.response.use(

const details = error.response?.data;

Log.error(error.message || "That didn't work.");
console.error(error.message || "That didn't work.");

if (details) console.log(JSON.stringify(details, null, 2));

Expand Down Expand Up @@ -239,7 +238,7 @@ export function create(resourceType, data, options = {}, callback = false) {
...requestConfig,
}).then(result => {
const details = `with response ${JSON.stringify(result.data, null, 2)}`;
Log.success(`Created ${resolvedResourceType} ${details}`);
console.log(`Created ${resolvedResourceType} ${details}`);

const { location } = result.headers;
if (location) console.log(`Record available @ ${location}`);
Expand Down Expand Up @@ -412,7 +411,7 @@ export function update(
data: resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Updated ${resolvedResourceType} at ${resolvedPath}`);
console.log(`Updated ${resolvedResourceType} at ${resolvedPath}`);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -461,7 +460,7 @@ export function get(resourceType, query, options = {}, callback = false) {
responseType: 'json',
...requestConfig,
}).then(result => {
Log.success(`Retrieved ${resolvedResourceType}`);
console.log(`Retrieved ${resolvedResourceType}`);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -528,7 +527,7 @@ export function upsert(
}
})
.then(result => {
Log.success(`Performed a "composed upsert" on ${resourceType}`);
console.log(`Performed a "composed upsert" on ${resourceType}`);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -675,7 +674,7 @@ export function patch(
data: resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Patched ${resolvedResourceType} at ${resolvedPath}`);
console.log(`Patched ${resolvedResourceType} at ${resolvedPath}`);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -724,7 +723,7 @@ export function destroy(
resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Deleted ${resolvedResourceType} at ${resolvedPath}`);
console.log(`Deleted ${resolvedResourceType} at ${resolvedPath}`);
return handleResponse(result, state, callback);
});
};
Expand Down
14 changes: 0 additions & 14 deletions packages/dhis2/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ export const CONTENT_TYPES = {
xls: 'application/vnd.ms-excel',
};

export class Log {
static success(message) {
return console.info(`✓ Success at ${new Date()}:\n∟`, message);
}

static warn(message) {
return console.warn(`⚠ Warning at ${new Date()}:\n∟`, message);
}

static error(message) {
return console.error(`✗ Error at ${new Date()}:\n∟`, message);
}
}

export function buildUrl(urlString, hostUrl, apiVersion) {
const pathSuffix = apiVersion ? `/${apiVersion}${urlString}` : `${urlString}`;
return hostUrl + '/api' + pathSuffix;
Expand Down

0 comments on commit bb79e16

Please sign in to comment.