-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): add utility for handling errors
- Loading branch information
1 parent
20da1f1
commit 70f701d
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* @adonisjs/ace | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { red, bgRed } from 'kleur' | ||
|
||
/** | ||
* Handles the command errors and prints them to the console. | ||
*/ | ||
export function handleError (error: any) { | ||
if (error.name === 'CommandValidationException') { | ||
console.log(red(error.message)) | ||
console.log(bgRed('This is a programming error. Make sure to read the docs')) | ||
return | ||
} | ||
|
||
if (error.name === 'InvalidArgumentException') { | ||
console.log(bgRed('Error')) | ||
console.log(red(error.message)) | ||
return | ||
} | ||
|
||
console.log(bgRed('Fatal error')) | ||
console.log(red(error.message)) | ||
console.log(error.stack) | ||
} |