Skip to content

[SyntaxError: Failed to parse JSON body: Unexpected token <] #243

Open

Description

I have the following piece of code.

// Method to generate manager with Q promises
function getFcmManager (socket) {
  // Define a client service constructor
  REST = restler.service(function (socket) {
    this.defaults.query = {
      // Query parameters here
    };
  }, {
    baseURL: API_PATH
  }, {
    POSTNOTIFICATION: function(object) {
      return this.post('send', {
        parser: restler.parsers.json,
        data: JSON.stringify(object),
        headers: {
          'Authorization': 'key=' + API_KEY,
          'Content-Type': 'application/json'
        }
      });
    }
  });
  // Create a client
  var rest = new REST(socket);
  // FCM manager
  var fcm = {
    // Post notification
    postnotification: function (token) {
      return Q.Promise(function (resolve, reject) {
        var settings = {
          notification: {
            title: "Notification title",  // Any value
            body: "Notification body",  // Any value
            sound: "default", // If you want notification sound
            click_action: "FCM_PLUGIN_ACTIVITY",  // Must be present for Android
            icon: "fcm_push_icon"  // White icon Android resource
          },
          data:{
            param1: "value1",  // Any data to be retrieved in the notification callback
            param2: "value2"
          },
          to: token, // Topic or single device
          priority: "high", // If not set, notification won't be delivered on completely closed iOS app
          restricted_package_name: "" // Optional. Set for application filtering
        }
        rest.POSTNOTIFICATION(settings).on('complete', function (data) {
          console.log('POSTNOTIFICATION', data);
          resolve(data);
        });
      });
    }
  }
  // Return
  return fcm;
}

And when I use:
fcm.postnotification(token);

It throws:
POSTNOTIFICATION [SyntaxError: Failed to parse JSON body: Unexpected token <]

Activity

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