art-standard-lib
Version:
The Standard Library for JavaScript that aught to be.
85 lines (68 loc) • 3.18 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var RequestError, compactFlatten, defineModule, formattedInspect, isFunction, merge, mergeInto, objectWithout, ref, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
defineModule = require('./CommonJs').defineModule;
formattedInspect = require('./Inspect').formattedInspect;
ref = require('./Core'), mergeInto = ref.mergeInto, isFunction = ref.isFunction, upperCamelCase = ref.upperCamelCase, compactFlatten = ref.compactFlatten, merge = ref.merge;
objectWithout = require('./ObjectExtensions').objectWithout;
/*
TODO:
Rename: ErrorWithProps
Rename: @info => @props
Only
*/
defineModule(module, RequestError = (function(superClass) {
extend(RequestError, superClass);
/*
IN:
props:
message: error-message
type: request-type (for REST, the Method/Verb)
key: request-key (for REST, the URL)
status: string, see: ArtCommunicationStatus for valid strings
data: error-response-data, if any
*/
function RequestError(props) {
var message, ref1, responseData, responseDataString, sourceLib;
RequestError.__super__.constructor.apply(this, arguments);
ref1 = this.props = merge(props), sourceLib = ref1.sourceLib, message = ref1.message, this.requestData = ref1.requestData, this.type = ref1.type, this.key = ref1.key, this.status = ref1.status, this.data = ref1.data, responseData = ref1.responseData;
this.responseData = this.data || (this.data = responseData);
this.name = (sourceLib || "") + " RequestError " + this.status;
if (this.props.data) {
delete this.props.data;
this.props.data = this.responseData;
}
responseDataString = this.data && formattedInspect({
data: this.data
});
this.message = message || compactFlatten([
(this.status || "failure") + ":", (responseDataString != null ? responseDataString.length : void 0) < 80 && !this.requestData ? [this.type, this.key, responseDataString] : "\n\n" + formattedInspect(merge({
type: this.type,
key: this.key,
requestData: this.requestData,
responseData: this.responseData
}))
]).join(' ');
if (this.props.stack) {
this.stack = this.props.stack;
this.props = objectWithout(this.props, "stack");
} else if (isFunction(Error.captureStackTrace)) {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error).stack;
}
this.info = this.props;
}
RequestError.prototype.toString = function() {
return [
this.name + ": " + this.message, formattedInspect({
props: this.props
})
].join("\n\n");
};
return RequestError;
})(Error));
}).call(this);
//# sourceMappingURL=RequestError.js.map