Skip to content

Problem in sending error report using Stacktrace.report #133

Description

@sarker306

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?

Activity

  1. oliversalzburg commented on Oct 13, 2015

    @oliversalzburg
    Contributor

    Can you check in DevTools what data is actually send?

  2. sarker306 commented on Oct 13, 2015

    @sarker306
    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.

  3. oliversalzburg commented on Oct 13, 2015

    @oliversalzburg
    Contributor

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

  4. eriwen commented on Oct 13, 2015

    @eriwen
    Member

    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

  5. oliversalzburg commented on Oct 13, 2015

    @oliversalzburg
    Contributor

    @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.

  6. eriwen commented on Oct 14, 2015

    @eriwen
    Member

    @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.

  7. oliversalzburg commented on Oct 14, 2015

    @oliversalzburg
    Contributor

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

  8. oliversalzburg commented on Oct 15, 2015

    @oliversalzburg
    Contributor

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

  9. sarker306 commented on Oct 18, 2015

    @sarker306
    Author

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

  10. oliversalzburg commented on Oct 18, 2015

    @oliversalzburg
    Contributor

    @sarker306 Awesome, thanks for verifying.

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

  11. added a commit that references this issue on Apr 16, 2016
    5aaaab3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions