ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Better error reporting #71

Open hypesystem opened 9 years ago

hypesystem commented 9 years ago

Currently, if an invalid request is made, all that is returned is the error code. The debug message (when running with DEBUG=node-gcm) is not any more helpful.

For example, I was trying to send a notification contianing a key from. This happens to be a reserved keyword. I had no way of knowing this, because all I was told was Invalid request 400.

A better model for the callbacks on error would be returning the body as well as the status-code:

        } else if (res.statusCode !== 200) {
            debug('Invalid request: ' + res.statusCode);
            return callback({
                status: res.statusCode
                response: resBody
            }, null);
        }

(Modified version of lines https://github.com/ToothlessGear/node-gcm/blob/2a293a6d795472a0886e0893891a4a0013b92800/lib/sender.js#L89-L92)

In my case, this gave me: '"data" key "from" is a reserved keyword\n' --- exactly what I needed to know.

hypesystem commented 9 years ago

I realize that this may break backwards compatibility. Since we're in sub-1.0 this might be acceptable ...

How many people actively depend on the error code returned on error? (My assumption is that most just print or log it.)

quinndiggity commented 8 years ago

+1

AdriVanHoudt commented 8 years ago

:+1: