opennms
Version:
Client API for the OpenNMS network monitoring platform
1 lines • 30.3 kB
JSON
{"remainingRequest":"/data/node_modules/babel-loader/lib/index.js!/data/node_modules/ts-loader/index.js!/data/src/rest/AbstractHTTP.ts","dependencies":[{"path":"/data/src/rest/AbstractHTTP.ts","mtime":1553611371628},{"path":"/data/node_modules/typescript-logging/dist/commonjs/typescript-logging.d.ts","mtime":1553611387808},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/LogGroupControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/CategoryServiceControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesToExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesFromExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionMessageJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionHelper.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/AbstractCategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/LoggerOptions.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryService.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryDelegateLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryMessageBufferImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/Logger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactory.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryService.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryRuntimeSettings.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/AbstractLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/ConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/MessageBufferLoggerImpl.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/DataStructures.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/JSONHelper.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/MessageUtils.d.ts","mtime":1553611387936},{"path":"/data/node_modules/moment/moment.d.ts","mtime":1553611386704},{"path":"/data/node_modules/axios/index.d.ts","mtime":1553611386356},{"path":"/data/typings/index.d.ts","mtime":1553611371628},{"path":"/data/node_modules/@types/fs-extra/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/inspector.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/minimatch/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/node_modules/@types/minimatch/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/handlebars/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/highlight.js/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jest/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jquery/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/lodash/index.d.ts","mtime":1553611386320},{"path":"/data/node_modules/@types/lodash/common/common.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/array.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/collection.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/date.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/function.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/lang.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/math.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/number.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/object.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/seq.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/string.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/util.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/marked/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/shelljs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/urijs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/typescript/lib/lib.es2015.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.core.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.collection.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.generator.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.promise.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.iterable.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.proxy.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.reflect.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es5.d.ts","mtime":1553611387388},{"path":"/data/node_modules/typescript/lib/lib.dom.d.ts","mtime":1553611387384},{"path":"/data/src/api/IOnmsHTTP.ts","mtime":1553611371624},{"path":"/data/src/api/IFilterProcessor.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsError.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsHTTPOptions.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsResult.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsServer.ts","mtime":1553611371624},{"path":"/data/src/rest/XmlTransformer.ts","mtime":1553611371628},{"path":"/data/src/rest/JsonTransformer.ts","mtime":1553611371628},{"path":"/data/.babelrc","mtime":1553611371556},{"path":"/data/node_modules/cache-loader/dist/cjs.js","mtime":1553611387012},{"path":"/data/node_modules/babel-loader/lib/index.js","mtime":1553611386992},{"path":"/data/node_modules/ts-loader/index.js","mtime":1553611386824}],"contextDependencies":[],"result":["\"use strict\";\n// tslint:disable-next-line\n/// <reference path=\"../../typings/index.d.ts\" />\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar OnmsError_1 = require(\"../api/OnmsError\");\nvar OnmsHTTPOptions_1 = require(\"../api/OnmsHTTPOptions\");\nvar XmlTransformer_1 = require(\"./XmlTransformer\");\nvar JsonTransformer_1 = require(\"./JsonTransformer\");\n/** @hidden */\nvar xmlTransformer = new XmlTransformer_1.XmlTransformer();\n/** @hidden */\nvar jsonTransformer = new JsonTransformer_1.JsonTransformer();\nvar OPTIONS_PROP = Symbol.for('options');\n/**\n * Abstract implementation of the OnmsHTTP interface meant to be extended by a concrete class.\n * @module AbstractHTTP\n * @implements IOnmsHTTP\n */\n\nvar AbstractHTTP = function () {\n /**\n * Create a new HTTP instance.\n * @constructor\n * @param server - A server object for immediate configuration.\n * @param timeout - How long to wait until timing out requests.\n */\n function AbstractHTTP(server, timeout) {\n _classCallCheck(this, AbstractHTTP);\n\n this[_a] = new OnmsHTTPOptions_1.OnmsHTTPOptions();\n if (server) {\n this.serverObj = server;\n }\n if (timeout) {\n this.options.timeout = timeout;\n }\n }\n /** The default set of HTTP options associated with this ReST client. */\n\n\n _createClass(AbstractHTTP, [{\n key: \"transformJSON\",\n\n /**\n * A convenience method for implementers to use to turn JSON into a javascript object.\n * Use this to process a JSON response before returning it in an [[OnmsResult]] object.\n */\n value: function transformJSON(data) {\n return jsonTransformer.transform(data);\n }\n /**\n * A convenience method for implementers to use to turn XML into a javascript object.\n * Use this to process an XML response before returning it in an [[OnmsResult]] object.\n */\n\n }, {\n key: \"transformXML\",\n value: function transformXML(data) {\n return xmlTransformer.transform(data);\n }\n /** Attempt to extract the data from a response. */\n\n }, {\n key: \"getData\",\n value: function getData(response) {\n var type = this.getType(response);\n if (type === 'json') {\n return this.transformJSON(response.data);\n } else if (type === 'xml') {\n return this.transformXML(response.data);\n } else {\n return response.data;\n }\n }\n /**\n * Attempt to determine the type of response.\n * @hidden\n */\n\n }, {\n key: \"getType\",\n value: function getType(response) {\n if (response.headers['content-type'] === 'application/json') {\n return 'json';\n } else if (response.config.responseType === 'json') {\n return 'json';\n } else if (response.config.headers.accept === 'application/json') {\n return 'json';\n } else if (response.responseType === 'json') {\n return 'json';\n } else if (response.config.headers.accept === 'application/xml') {\n return 'xml';\n } else if (response.headers['content-type'] === 'application/xml') {\n return 'xml';\n }\n return 'text';\n }\n /**\n * Get the [[OnmsServer]] object that should be used for making requests. Favors the one\n * passed in the [[OnmsHTTPOptions]], otherwise it falls back to the default server associated\n * with the HTTP implementation.\n */\n\n }, {\n key: \"getServer\",\n value: function getServer(options) {\n if (options && options.server) {\n return options.server;\n }\n return this.serverObj;\n }\n /**\n * Get the union of [[OnmsHTTPOptions]] based on the passed options, defaults,\n * and options in the [[OnmsServer]] associated with this request. Order of\n * precedence is passed options -> server options -> default options.\n */\n\n }, {\n key: \"getOptions\",\n value: function getOptions(options) {\n var ret = new OnmsHTTPOptions_1.OnmsHTTPOptions();\n Object.assign(ret, this.options);\n var server = this.getServer(options);\n ret.server = server;\n if (server && server.auth) {\n ret.auth = Object.assign(ret.auth, server.auth);\n }\n Object.assign(ret, options);\n if (!ret.headers.hasOwnProperty('X-Requested-With')) {\n ret.headers['X-Requested-With'] = 'XMLHttpRequest';\n }\n return ret;\n }\n /**\n * Implementers should override this method if they have actions that need to be performed\n * (like clearing a cache) when server settings change.\n */\n\n }, {\n key: \"onSetServer\",\n value: function onSetServer() {}\n // do nothing by default\n\n /**\n * Create an [[OnmsError]] from an error response.\n * @hidden\n */\n\n }, {\n key: \"handleError\",\n value: function handleError(err, options) {\n var message = AbstractHTTP.extractMessage(err);\n var status = AbstractHTTP.extractStatus(err);\n var data = AbstractHTTP.extractData(err);\n return new OnmsError_1.OnmsError(message, status, options, data);\n }\n /* tslint:disable:member-ordering */\n /**\n * Attempt to determine an error message from an error response.\n * @hidden\n */\n\n }, {\n key: \"options\",\n get: function get() {\n if (this[OPTIONS_PROP]) {\n return this[OPTIONS_PROP];\n }\n return {};\n },\n set: function set(o) {\n this[OPTIONS_PROP] = o;\n }\n /**\n * The default amount of time to wait before giving up on a request.\n * @deprecated Set `timeout` on the [[OnmsHTTPOptions]] object instead. This will go away in OpenNMS.js 2.0.\n */\n\n }, {\n key: \"timeout\",\n get: function get() {\n return this.options.timeout;\n },\n set: function set(t) {\n /* tslint:disable:no-console */\n console.warn('The \"timeout\" property on OnmsHTTP implementations is deprecated ' + 'and will be removed in OpenNMS.js 2. Use \"options.timeout\" instead.');\n this.options.timeout = t;\n }\n /** The server associated with this HTTP implementation. */\n\n }, {\n key: \"server\",\n get: function get() {\n return this.serverObj;\n },\n set: function set(server) {\n this.serverObj = server;\n this.onSetServer();\n }\n }], [{\n key: \"extractMessage\",\n value: function extractMessage(err) {\n if (err) {\n if (err.message) {\n return err.message;\n } else if (err.response) {\n return this.extractMessage(err.response);\n } else if (err.data && Object.prototype.toString.call(err) === '[object String]') {\n return err.data;\n } else if (err.statusText) {\n return err.statusText;\n }\n return JSON.stringify(err);\n }\n return 'no error message';\n }\n /**\n * Attempt to determine an error status code from an error response.\n * @hidden\n */\n\n }, {\n key: \"extractStatus\",\n value: function extractStatus(err) {\n var status = -1;\n if (err.code) {\n status = err.code;\n } else if (err.status) {\n status = err.status;\n } else if (err.response && err.response.status) {\n status = err.response.status;\n }\n return status;\n }\n /**\n * Attempt to determine the data in an error response.\n * @hidden\n */\n\n }, {\n key: \"extractData\",\n value: function extractData(err) {\n if (err && err.response && err.response.data) {\n return err.response.data;\n }\n return undefined;\n }\n }]);\n\n return AbstractHTTP;\n}();\n\n_a = OPTIONS_PROP;\nexports.AbstractHTTP = AbstractHTTP;\nvar _a;",{"version":3,"file":"/data/src/rest/AbstractHTTP.ts","sourceRoot":"","sources":["/data/src/rest/AbstractHTTP.ts"],"names":[],"mappings":";AAAA,AAA2B;AAC3B,AAAiD;;;;;;;AAKjD,0BAA2C;AAC3C,gCAAuD;AAGvD,+BAAgD;AAChD,gCAAkD;AAElD,AAAc;AACd,IAAM,AAAc,iBAAG,IAAI,iBAAc,AAAE,AAAC;AAE5C,AAAc;AACd,IAAM,AAAe,kBAAG,IAAI,kBAAe,AAAE,AAAC;AAE9C,IAAM,AAAY,eAAG,AAAM,OAAC,AAAG,IAAC,AAAS,AAAC,AAAC;AAE3C,AAIG,AACH;;;;;;;AA8CE,AAKG;;;;;;AACH,0BAAY,AAAmB,QAAE,AAAgB;;;AAnDzC,aAAc,MAAG,IAAI,kBAAe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AAC,AAAI,KAAC,AAAS,UAAC,AAAG,AAAC,AAAC,AAC7B;AAAC;AACD,AAAM,mBAAC,AAAkB,AAAC,AAC5B;AAAC;AAED,AAGG,AACO,AAAM,AAAC,AAAa;;;;;;;sCAAC,AAAQ;AACrC,gBAAI,AAAM,SAAG,CAAC,AAAC,AAAC;AAChB,AAAE,AAAC,gBAAC,AAAG,IAAC,AAAI,AAAC,MAAC,AAAC;AACb,AAAM,yBAAG,AAAG,IAAC,AAAI,AAAC,AACpB;AAAC,AAAC,AAAI,uBAAK,AAAG,IAAC,AAAM,AAAC,QAAC,AAAC;AACtB,AAAM,yBAAG,AAAG,IAAC,AAAM,AAAC,AACtB;AAAC,AAAC,AAAI,aAFC,AAAE,AAAC,MAEH,AAAE,AAAC,IAAC,AAAG,IAAC,AAAQ,YAAI,AAAG,IAAC,AAAQ,SAAC,AAAM,AAAC,QAAC,AAAC;AAC/C,AAAM,yBAAG,AAAG,IAAC,AAAQ,SAAC,AAAM,AAAC,AAC/B;AAAC;AACD,AAAM,mBAAC,AAAM,AAAC,AAChB;AAAC;AAED,AAGG,AACO,AAAM,AAAC,AAAW;;;;;;;oCAAC,AAAQ;AACnC,AAAE,AAAC,gBAAC,AAAG,OAAI,AAAG,IAAC,AAAQ,YAAI,AAAG,IAAC,AAAQ,SAAC,AAAI,AAAC,MAAC,AAAC;AAC7C,AAAM,uBAAC,AAAG,IAAC,AAAQ,SAAC,AAAI,AAAC,AAC3B;AAAC;AACD,AAAM,mBAAC,AAAS,AAAC,AACnB;AAAC,AAEF;;;;;;KA9NU,AAAY;AADvB,uBA+NC","sourcesContent":["// tslint:disable-next-line\n/// <reference path=\"../../typings/index.d.ts\" />\n\nimport {IOnmsHTTP} from '../api/IOnmsHTTP';\nimport {IFilterProcessor} from '../api/IFilterProcessor';\n\nimport {OnmsError} from '../api/OnmsError';\nimport {OnmsHTTPOptions} from '../api/OnmsHTTPOptions';\nimport {OnmsResult} from '../api/OnmsResult';\nimport {OnmsServer} from '../api/OnmsServer';\nimport {XmlTransformer} from './XmlTransformer';\nimport {JsonTransformer} from './JsonTransformer';\n\n/** @hidden */\nconst xmlTransformer = new XmlTransformer();\n\n/** @hidden */\nconst jsonTransformer = new JsonTransformer();\n\nconst OPTIONS_PROP = Symbol.for('options');\n\n/**\n * Abstract implementation of the OnmsHTTP interface meant to be extended by a concrete class.\n * @module AbstractHTTP\n * @implements IOnmsHTTP\n */\nexport abstract class AbstractHTTP implements IOnmsHTTP {\n private [OPTIONS_PROP] = new OnmsHTTPOptions();\n\n /** The default set of HTTP options associated with this ReST client. */\n public get options(): OnmsHTTPOptions {\n if (this[OPTIONS_PROP]) {\n return this[OPTIONS_PROP];\n }\n return {} as OnmsHTTPOptions;\n }\n\n public set options(o: OnmsHTTPOptions) {\n this[OPTIONS_PROP] = o;\n }\n\n /**\n * The default amount of time to wait before giving up on a request.\n * @deprecated Set `timeout` on the [[OnmsHTTPOptions]] object instead. This will go away in OpenNMS.js 2.0.\n */\n public get timeout(): number {\n return this.options.timeout;\n }\n\n public set timeout(t: number) {\n /* tslint:disable:no-console */\n console.warn('The \"timeout\" property on OnmsHTTP implementations is deprecated ' +\n 'and will be removed in OpenNMS.js 2. Use \"options.timeout\" instead.');\n this.options.timeout = t;\n }\n\n /**\n * The server metadata we'll use for constructing ReST calls.\n * @hidden\n */\n private serverObj: OnmsServer;\n\n /** The server associated with this HTTP implementation. */\n public get server() {\n return this.serverObj;\n }\n\n public set server(server: OnmsServer) {\n this.serverObj = server;\n this.onSetServer();\n }\n\n /**\n * Create a new HTTP instance.\n * @constructor\n * @param server - A server object for immediate configuration.\n * @param timeout - How long to wait until timing out requests.\n */\n constructor(server?: OnmsServer, timeout?: number) {\n if (server) {\n this.serverObj = server;\n }\n if (timeout) {\n this.options.timeout = timeout;\n }\n }\n\n /** Make an HTTP GET call. This must be implemented by the concrete implementation. */\n public abstract get(url: string, options?: OnmsHTTPOptions): Promise<OnmsResult<any>>;\n\n /** Make an HTTP PUT call. This must be overridden by the concrete implementation. */\n public abstract put(url: string, options?: OnmsHTTPOptions): Promise<OnmsResult<any>>;\n\n /** Make an HTTP POST call. This must be overridden by the concrete implementation. */\n public abstract post(url: string, options?: OnmsHTTPOptions): Promise<OnmsResult<any>>;\n\n /** Make an HTTP DELETE call. This must be overridden by the concrete implementation. */\n public abstract httpDelete(url: string, options?: OnmsHTTPOptions): Promise<OnmsResult<any>>;\n\n /**\n * A convenience method for implementers to use to turn JSON into a javascript object.\n * Use this to process a JSON response before returning it in an [[OnmsResult]] object.\n */\n protected transformJSON(data: any) {\n return jsonTransformer.transform(data);\n }\n\n /**\n * A convenience method for implementers to use to turn XML into a javascript object.\n * Use this to process an XML response before returning it in an [[OnmsResult]] object.\n */\n protected transformXML(data: any) {\n return xmlTransformer.transform(data);\n }\n\n /** Attempt to extract the data from a response. */\n protected getData(response: any) {\n const type = this.getType(response);\n if (type === 'json') {\n return this.transformJSON(response.data);\n } else if (type === 'xml') {\n return this.transformXML(response.data);\n } else {\n return response.data;\n }\n }\n\n /**\n * Attempt to determine the type of response.\n * @hidden\n */\n protected getType(response: any) {\n if (response.headers['content-type'] === 'application/json') {\n return 'json';\n } else if (response.config.responseType === 'json') {\n return 'json';\n } else if (response.config.headers.accept === 'application/json') {\n return 'json';\n } else if (response.responseType === 'json') {\n return 'json';\n } else if (response.config.headers.accept === 'application/xml') {\n return 'xml';\n } else if (response.headers['content-type'] === 'application/xml') {\n return 'xml';\n }\n return 'text';\n }\n\n /**\n * Get the [[OnmsServer]] object that should be used for making requests. Favors the one\n * passed in the [[OnmsHTTPOptions]], otherwise it falls back to the default server associated\n * with the HTTP implementation.\n */\n protected getServer(options?: OnmsHTTPOptions) {\n if (options && options.server) {\n return options.server;\n }\n return this.serverObj;\n }\n\n /**\n * Get the union of [[OnmsHTTPOptions]] based on the passed options, defaults,\n * and options in the [[OnmsServer]] associated with this request. Order of\n * precedence is passed options -> server options -> default options.\n */\n protected getOptions(options?: OnmsHTTPOptions): OnmsHTTPOptions {\n const ret = new OnmsHTTPOptions();\n Object.assign(ret, this.options);\n\n const server = this.getServer(options);\n ret.server = server;\n if (server && server.auth) {\n ret.auth = Object.assign(ret.auth, server.auth);\n }\n Object.assign(ret, options);\n if (!ret.headers.hasOwnProperty('X-Requested-With')) {\n ret.headers['X-Requested-With'] = 'XMLHttpRequest';\n }\n return ret;\n }\n\n /**\n * Implementers should override this method if they have actions that need to be performed\n * (like clearing a cache) when server settings change.\n */\n protected onSetServer() {\n // do nothing by default\n }\n\n /**\n * Create an [[OnmsError]] from an error response.\n * @hidden\n */\n protected handleError(err: any, options?: any): OnmsError {\n const message = AbstractHTTP.extractMessage(err);\n const status = AbstractHTTP.extractStatus(err);\n const data = AbstractHTTP.extractData(err);\n return new OnmsError(message, status, options, data);\n }\n\n /* tslint:disable:member-ordering */\n\n /**\n * Attempt to determine an error message from an error response.\n * @hidden\n */\n protected static extractMessage(err: any): string {\n if (err) {\n if (err.message) {\n return err.message;\n } else if (err.response) {\n return this.extractMessage(err.response);\n } else if (err.data && Object.prototype.toString.call(err) === '[object String]') {\n return err.data;\n } else if (err.statusText) {\n return err.statusText;\n }\n return JSON.stringify(err);\n }\n return 'no error message';\n }\n\n /**\n * Attempt to determine an error status code from an error response.\n * @hidden\n */\n protected static extractStatus(err: any): number {\n let status = -1;\n if (err.code) {\n status = err.code;\n } else if (err.status) {\n status = err.status;\n } else if (err.response && err.response.status) {\n status = err.response.status;\n }\n return status;\n }\n\n /**\n * Attempt to determine the data in an error response.\n * @hidden\n */\n protected static extractData(err: any): any {\n if (err && err.response && err.response.data) {\n return err.response.data;\n }\n return undefined;\n }\n\n}\n"]}]}