feat(messaging): implement Messaging class for structured error handling
This commit is contained in:
		
							parent
							
								
									da36715b3b
								
							
						
					
					
						commit
						72769a3ef4
					
				
					 1 changed files with 18 additions and 0 deletions
				
			
		
							
								
								
									
										18
									
								
								scripts/utilities/messaging.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								scripts/utilities/messaging.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | ||||||
|  | class Messaging { | ||||||
|  |     /*  | ||||||
|  |     Return an error message.  | ||||||
|  | 
 | ||||||
|  |     @param {object} INSTANCE - The response instance | ||||||
|  |     @param {object} ERROR - The error object | ||||||
|  |     */ | ||||||
|  |     static exception (INSTANCE, ERROR) { | ||||||
|  |         let MESSAGE = {"error": {}}; | ||||||
|  |         [`name`, `message`, `stack`].forEach((KEY) => { | ||||||
|  |             MESSAGE[`error`][KEY] = ERROR[KEY]; | ||||||
|  |         }) | ||||||
|  |         INSTANCE.json(MESSAGE); console.error(ERROR); | ||||||
|  |         return (MESSAGE); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | module.exports = Messaging; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue