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

Do not error if a host is specified; useful for locally-run instances of ORS. #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/OrsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import Constants from './constants.js'
const orsUtil = new OrsUtil()

class OrsBase {
constructor(args) {
constructor(constructorArgs) {
this.defaultArgs = {}
this.requestArgs = {}
this.argsCache = null
this.customHeaders = {}

this._setRequestDefaults(args)
this._setRequestDefaults(constructorArgs)
}

/**
* Set defaults for a request comparing with and overwriting default class arguments
* @param {Object} args - constructor input
*/
_setRequestDefaults(args) {
_setRequestDefaults(constructorArgs) {
this.defaultArgs[Constants.propNames.host] = Constants.defaultHost
if (args[Constants.propNames.host]) {
this.defaultArgs[Constants.propNames.host] = args[Constants.propNames.host]
if (constructorArgs[Constants.propNames.host]) {
this.defaultArgs[Constants.propNames.host] = constructorArgs[Constants.propNames.host]
}
if (args[Constants.propNames.service]) {
this.defaultArgs[Constants.propNames.service] = args[Constants.propNames.service]
if (constructorArgs[Constants.propNames.service]) {
this.defaultArgs[Constants.propNames.service] = constructorArgs[Constants.propNames.service]
}
if (Constants.propNames.apiKey in args) {
this.defaultArgs[Constants.propNames.apiKey] = args[Constants.propNames.apiKey]
} else {

if (Constants.propNames.apiKey in constructorArgs) {
this.defaultArgs[Constants.propNames.apiKey] = constructorArgs[Constants.propNames.apiKey]
}
else if (!constructorArgs[Constants.propNames.host]) {
// Do not error if a host is specified; useful for locally-run instances of ORS
// eslint-disable-next-line no-console
console.error(Constants.missingAPIKeyMsg)
throw new Error(Constants.missingAPIKeyMsg)
Expand Down