You should use ESLint and Prettier, which will warn you when you'll try to write unreadable and excessive code like this:
!error.message ? err = {"message": error} : err = error;
and change it like this:
err = !error.message ? {"message": error} : error;
There is even an ESLint rule for preventing using ternary operators all together:
disallow ternary operators (no-ternary)
The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.
And that's for normal assignment usage, not even for procedural usage like you're doing in your code.