Handler mixin for writing JSON errors