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

dhis2 remove Class Log #417

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
46 changes: 35 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,8 @@ export function execute(...operations) {
function configMigrationHelper(state) {
const { hostUrl, apiUrl } = state.configuration;
if (!hostUrl) {
Log.warn(
console.warn(
`⚠ Warning at ${new Date()}:\n∟`,
'DEPRECATION WARNING: Please migrate instance address from `apiUrl` to `hostUrl`.'
);
state.configuration.hostUrl = apiUrl;
Expand All @@ -82,7 +82,7 @@ axios.interceptors.response.use(
responseData: response.data,
};

Log.error(newError.message);
console.error(`✗ Error at ${new Date()}:\n∟`, newError.message);
mtuchi marked this conversation as resolved.
Show resolved Hide resolved

return Promise.reject(newError);
}
Expand All @@ -96,7 +96,10 @@ 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(
`⚠ Warning at ${new Date()}:\n∟`,
mtuchi marked this conversation as resolved.
Show resolved Hide resolved
'Non-JSON response detected, unable to parse.'
);
}
}
return response;
Expand All @@ -107,7 +110,10 @@ axios.interceptors.response.use(

const details = error.response?.data;

Log.error(error.message || "That didn't work.");
console.error(
`✗ Error at ${new Date()}:\n∟`,
mtuchi marked this conversation as resolved.
Show resolved Hide resolved
error.message || "That didn't work."
);

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

Expand Down Expand Up @@ -239,7 +245,10 @@ 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(
`✓ Success at ${new Date()}:\n∟`,
`Created ${resolvedResourceType} ${details}`
);

const { location } = result.headers;
if (location) console.log(`Record available @ ${location}`);
Expand Down Expand Up @@ -412,7 +421,10 @@ export function update(
data: resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Updated ${resolvedResourceType} at ${resolvedPath}`);
console.log(
`✓ Success at ${new Date()}:\n∟`,
`Updated ${resolvedResourceType} at ${resolvedPath}`
);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -461,7 +473,10 @@ export function get(resourceType, query, options = {}, callback = false) {
responseType: 'json',
...requestConfig,
}).then(result => {
Log.success(`Retrieved ${resolvedResourceType}`);
console.log(
`✓ Success at ${new Date()}:\n∟`,
`Retrieved ${resolvedResourceType}`
);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -528,7 +543,10 @@ export function upsert(
}
})
.then(result => {
Log.success(`Performed a "composed upsert" on ${resourceType}`);
console.log(
`✓ Success at ${new Date()}:\n∟`,
`Performed a "composed upsert" on ${resourceType}`
);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -675,7 +693,10 @@ export function patch(
data: resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Patched ${resolvedResourceType} at ${resolvedPath}`);
console.log(
`✓ Success at ${new Date()}:\n∟`,
`Patched ${resolvedResourceType} at ${resolvedPath}`
);
return handleResponse(result, state, callback);
});
};
Expand Down Expand Up @@ -724,7 +745,10 @@ export function destroy(
resolvedData,
...requestConfig,
}).then(result => {
Log.success(`Deleted ${resolvedResourceType} at ${resolvedPath}`);
console.log(
`✓ Success at ${new Date()}:\n∟`,
`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