'use strict'; var util = require('util'); var isArrayish = require('is-arrayish'); var errorEx = function errorEx(name, properties) { if (!name || name.constructor !== String) { properties = name || {}; name = Error.name; } var errorExError = function ErrorEXError(message) { if (!this) { return new ErrorEXError(message); } message = message instanceof Error ? message.message : (message || this.message); Error.call(this, message); Error.captureStackTrace(this, errorExError); this.name = name; delete this.message; Object.defineProperty(this, 'message', { configurable: true, enumerable: false, get: function () { var newMessage = message.split(/\r?\n/g); for (var key in properties) { if (properties.hasOwnProperty(key) && 'message' in properties[key]) { newMessage = properties[key].message(this[key], newMessage) || newMessage; if (!isArrayish(newMessage)) { newMessage = [newMessage]; } } } return newMessage.join('\n'); }, set: function (v) { message = v; } }); var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack'); var stackGetter = stackDescriptor.get; stackDescriptor.get = function () { var stack = stackGetter.call(this).split(/\r?\n+/g); var lineCount = 1; for (var key in properties) { if (!properties.hasOwnProperty(key)) { continue; } var modifier = properties[key]; if ('line' in modifier) { var line = modifier.line(this[key]); if (line) { stack.splice(lineCount, 0, ' ' + line); } } if ('stack' in modifier) { modifier.stack(this[key], stack); } } return stack.join('\n'); }; Object.defineProperty(this, 'stack', stackDescriptor); }; util.inherits(errorExError, Error); return errorExError; }; errorEx.append = function (str, def) { return { message: function (v, message) { v = v || def; if (v) { message[0] += ' ' + str.replace('%s', v.toString()); } return message; } }; }; errorEx.line = function (str, def) { return { line: function (v) { v = v || def; if (v) { return str.replace('%s', v.toString()); } return null; } }; }; module.exports = errorEx;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/error-ex/index.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |