amplitude / Amplitude-JavaScript

JavaScript SDK for Amplitude
MIT License
315 stars 133 forks source link

Wrong event can't be handled #241

Open koshevy opened 4 years ago

koshevy commented 4 years ago

utils.validateProperties brakes wrong events silently (https://github.com/amplitude/Amplitude-JavaScript/blob/v5.10.0/src/utils.js#L102). It only logs errors to console, but don't provide ability to catch this as an error.

haoliu-amp commented 4 years ago

Hello! Besides error message, what else do you wanna have here? An error callback listener?

koshevy commented 4 years ago

@haoliu-amp Hello! At least, I would like to get correct response (i.e. error response) in already existed callback-param passed to AmplitudeClient.prototype.logEvent:

amplitudeClient.logEvent(eventType, data, (code, status, details) => {
    if (code === 200 && status === 'success') {
        observer.next();
        observer.complete();

        return;
    }

    const reason = (details && details.reason) ? details.reason : 'Unknown reason';
    const error = new Error([
        `Event ${eventType} failed with data ${JSON.stringify(data)}.`,
        `Code and status are: ${code}, ${status}.`,
        `The reason is: ${reason}`,
    ].join(' '));

    // I want to get it here, but this place never will be reached if event is wrong
    observer.error(error);
});

So, this situation is related with #242. We can't handle error at sending and also we can't continue to use logEvent. It all does work unstable — we cant controlling our work with statistics and can't be confident and can't make tests efficiently.