1818var has = require ( 'lodash.has' ) ;
1919var is = require ( 'is' ) ;
2020var isObject = is . object ;
21- var isString = is . string ;
22- var isNumber = is . number ;
23- var isFunction = is . function ;
2421var buildStackTrace = require ( './build-stack-trace.js' ) ;
2522
2623/**
@@ -35,17 +32,13 @@ var buildStackTrace = require('./build-stack-trace.js');
3532 */
3633function populateErrorMessage ( ob , em ) {
3734 if ( ob === null || ob === undefined ) {
38- populateFromUnknown ( ob , em ) ;
39- } else if ( ob instanceof Error ) {
35+ em . setMessage ( buildStackTrace ( '' + ob , 3 ) ) ;
36+ } else if ( ob . stack ) {
4037 populateFromError ( ob , em ) ;
4138 } else if ( typeof ob === 'object' && isObject ( ob ) ) {
4239 populateFromObject ( ob , em ) ;
43- } else if ( typeof ob === 'string' && isString ( ob ) ) {
44- populateFromString ( ob , em ) ;
45- } else if ( typeof ob === 'number' ) {
46- populateFromNumber ( ob , em ) ;
4740 } else {
48- populateFromUnknown ( ob , em ) ;
41+ em . setMessage ( buildStackTrace ( ob . toString ( ) , 3 ) ) ;
4942 }
5043
5144 return em ;
@@ -129,51 +122,4 @@ function populateFromObject(ob, errorMessage) {
129122 }
130123}
131124
132- /**
133- * Handles validation of an error which has been indicated to be of type String.
134- * This function will create a new instance of the Error class to produce a
135- * stack trace for submission to the API and check to confirm that the given
136- * value is of type string.
137- * @function populateFromString
138- * @param {String } str - the String indicated as the content of the error
139- * @param {ErrorMessage } errorMessage - the error message instance to marshal
140- * error information into.
141- * @returns {Undefined } - does not return anything
142- */
143- function populateFromString ( str , errorMessage ) {
144- errorMessage . setMessage ( buildStackTrace ( str , 3 ) ) ;
145- }
146-
147- /**
148- * Handles routing and validation for parsing an error which has been indicated
149- * to be of type Number. This handler will manufacture a new Error to create
150- * a stack-trace for submission to the Error API and will attempt to caste the
151- * given number to a string for submission to the Error API.
152- * @function populateFromNumber
153- * @param {Number } num - the number submitted as content for the error message
154- * @param {ErrorMessage } errorMessage - the error messag instance to marshall
155- * error information into.
156- * @returns {Undefined } - does not return anything
157- */
158- function populateFromNumber ( num , errorMessage ) {
159- var message = isNumber ( num ) && isFunction ( num . toString ) ? num . toString ( ) : '' ;
160- errorMessage . setMessage ( buildStackTrace ( message , 3 ) ) ;
161- }
162-
163- /**
164- * Handles unknown/unsupported input as the content of the error message. Since
165- * the problem-space is not defined for this path the library only attempts to
166- * manufacture a stack trace for submission to the API and discards the input
167- * that was given as the error content.
168- * @function populateFromUnknown
169- * @param {Any } ob - the unknown/unsupported input indicated as the content of
170- * the error.
171- * @param {ErrorMessage } errorMessage - the error message instance to marshal
172- * error information into.
173- * @returns {Undefined } - does not return anything
174- */
175- function populateFromUnknown ( ob , errorMessage ) {
176- errorMessage . setMessage ( buildStackTrace ( '' + ob , 3 ) ) ;
177- }
178-
179125module . exports = populateErrorMessage ;
0 commit comments