Skip to content

Commit

Permalink
Rename misleadingly-named OkapiSession.logger member (#68)
Browse files Browse the repository at this point in the history
TECH DEBT: The `OkapiSession`'s config object is now in its `cfg`
member, not `logger`.

We got away with this weirdness until recently because the only thing
the Okapi session used its config object for was logging.

Fixes PR-2095.
  • Loading branch information
MikeTaylor authored Jan 13, 2025
1 parent 94e5f37 commit 7de148f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Support per-service config item `alwaysShowForm` to specify that the full form always should be displayed once for confirmation even when the submitted OpenURL has complete basic metadata. Update docs. Fixes PR-2059.
* Add Service Level field to blank request form. Fixes PR-2056.
* Add maximum cost field-pair (`maximumCostsMonetaryValue` and `maximumCostsCurrencyCode`) to blank request form. Fixes PR-2058.
* TECH DEBT: The `OkapiSession`'s config object is now in its `cfg` member, not `logger`. Fixes PR-2095.

## [1.6.0](https://github.com/openlibraryenvironment/listener-openurl/tree/v1.6.0) (2024-03-04)

Expand Down
10 changes: 5 additions & 5 deletions src/OkapiSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const HTTPError = require('./HTTPError');

class OkapiSession {
constructor(cfg, label = 'main', values) {
this.logger = cfg;
this.cfg = cfg;
this.label = label;
if (!values) values = cfg.getValues();
if (values.withoutOkapi) return;
Expand All @@ -22,7 +22,7 @@ class OkapiSession {

login() {
const { username, password } = this;
this.logger.log('okapi', `logging into Okapi session '${this.label}' as ${username}/${password}`);
this.cfg.log('okapi', `logging into Okapi session '${this.label}' as ${username}/${password}`);
this.token = undefined;
return this.okapiFetch('POST', '/authn/login', { username, password }, true)
.then(res => {
Expand All @@ -32,15 +32,15 @@ class OkapiSession {
}

async _getDataFromReShare(path, caption) {
if (this.logger.values?.withoutOkapi) {
if (this.cfg.values?.withoutOkapi) {
// Running as part of a test: do nothing
return {};
}

const res = await this.okapiFetch('GET', path);
if (res.status !== 200) throw new HTTPError(res, `cannot fetch default ${caption} for '${this.label}'`);
const json = await res.json();
this.logger.log('json', this.label, JSON.stringify(json, null, 2));
this.cfg.log('json', this.label, JSON.stringify(json, null, 2));
return json;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ class OkapiSession {
'x-okapi-tenant': this.tenant,
};
if (this.token) headers['x-okapi-token'] = this.token;
this.logger.log('okapi', `okapiFetch ${method} for session '${this.label}' at ${path}`);
this.cfg.log('okapi', `okapiFetch ${method} for session '${this.label}' at ${path}`);
return fetch(`${this.okapiUrl}${path}`, {
method,
body: payload ? JSON.stringify(payload) : undefined,
Expand Down

0 comments on commit 7de148f

Please sign in to comment.