mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-26 17:56:13 -04:00
fix(integer-base-converter): handle non-decimal char and better error message
This commit is contained in:
parent
0ff853437b
commit
8476cf319b
4 changed files with 93 additions and 11 deletions
24
src/utils/error.ts
Normal file
24
src/utils/error.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
export { getErrorMessageIfThrows };
|
||||
|
||||
function getErrorMessageIfThrows(cb: () => unknown) {
|
||||
try {
|
||||
cb();
|
||||
return undefined;
|
||||
} catch (err) {
|
||||
if (_.isString(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (_.isError(err)) {
|
||||
return err.message;
|
||||
}
|
||||
|
||||
if (_.isObject(err) && _.has(err, 'message')) {
|
||||
return (err as { message: string }).message;
|
||||
}
|
||||
|
||||
return 'An error as occurred.';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue