Skip to content

Problem in sending error report using Stacktrace.report #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sarker306 opened this issue Oct 13, 2015 · 10 comments
Closed

Problem in sending error report using Stacktrace.report #133

sarker306 opened this issue Oct 13, 2015 · 10 comments

Comments

@sarker306
Copy link

I am using express 4.0 and I'm trying to send client side error from my angular app to server. I have exposed StackTrace as an angular service stacktraceService.

If I catch the error manually, and send them via a POST request like this:

     stacktraceService.StackTrace
        .fromError(exception)
        .then(function(stackframes){
            console.log(stackframes);
            $.ajax({
                type: "POST",
                url: "./error",
                contentType: "application/json",
                data: angular.toJson({
                    stack: stackframes
                })
            });
        });

The server side code can parse the req.body using "json()" method of express/body-parser and show it correctly.

However, if I use the stacktrace.js report functionality, like,

      stacktraceService.StackTrace
        .fromError(exception)
        .then(function(stackframes){
            console.log(stackframes);
            stacktraceService.StackTrace
            .report(stackframes, './error');
        });

,then the server side code finds the req.body undefined.

I was wondering what the cause would be. Am I using .report() functionality wrong?

@oliversalzburg
Copy link
Member

Can you check in DevTools what data is actually send?

@sarker306
Copy link
Author

Before sending data, I console.logged the stackframes found from fromError, it logged nicely in browser console. From Network tab of DevTools, I found the request payload contains [Object object]. I am not exactly sure how to see inside this Object array being sent, though.

@oliversalzburg
Copy link
Member

I'm assuming .report() improperly serializes the input to string (by not doing anything). It should use JSON.stringify to convert the input.

@eriwen
Copy link
Member

eriwen commented Oct 13, 2015

I think you're right, @oliversalzburg. Would you have a bit of time to submit a PR for this? It should be noted that JSON.stringify() is IE8+ only so we may have to provide a polyfill in polyfills.js

@oliversalzburg
Copy link
Member

@eriwen Happy to do it. I've pretty much always used abstractions over XHR, so I'm not familiar with browser differences. Do you think a simple stringify will suffice?

For the polyfill, I'd probably go with JSON3 if you don't have a different suggestion.

@eriwen
Copy link
Member

eriwen commented Oct 14, 2015

@oliversalzburg My gut says a simple stringify will suffice. I don't think this an issue with our use of XHR - I've been using this method forever.

JSON3 seems like a good choice for a polyfill.

@oliversalzburg
Copy link
Member

@eriwen I'll try to submit a PR tonight, shouldn't be too much work. :)

@oliversalzburg
Copy link
Member

@sarker306 It would be cool if you could give #135 a try.

@sarker306
Copy link
Author

I tried this fix, and yeah, it works nicely. Thanks a lot.

@oliversalzburg
Copy link
Member

@sarker306 Awesome, thanks for verifying.

I will publish a new version next week unless I can squeeze it in tonight :)

eriwen pushed a commit that referenced this issue Apr 16, 2016
Includes JSON3 in the polyfill version
Fixes #133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants