Subclass Error and implement toJSON

The returned error can be converted to json with JSON.stringify.