Normalize the client-side error to have a proper Error instance

I would like to have another pair of eyes here.
Can you think of a better way to solve this?