HaxeFoundation / hx3compat

Haxe 3 compatibility lib for Haxe 4
MIT License
16 stars 16 forks source link

remoting HttpConnection exceptions #18

Open filt3rek opened 3 years ago

filt3rek commented 3 years ago

Hej,

For those who still use haxe remoting, with Haxe 4, exceptions are not very pretty when sended back to the client. So I have done a small modification in HttpConnection.hx like that :

public static function processRequest( requestData : String, ctx : Context ) : String {
        try {
            var u = new haxe.Unserializer(requestData);
            var path = u.unserialize();
            var args = u.unserialize();
            var data = ctx.call(path,args);
            var s = new haxe.Serializer();
            s.serialize(data);
            return "hxr" + s.toString();
        } catch( e ) {
            var s = new haxe.Serializer();
#if (haxe_ver >= 4)
            s.serializeException( e.message + "\r\n" + e.details() );
#else
            s.serializeException( e );
#end
            return "hxr" + s.toString();
        }
    }