Getting message: "Match failed [400]", errorType: "Meteor.Error" when using rocketchat methods(loadHistory) in Reactjs

2.2k Views Asked by At

I am trying to integrate Rocket chat to my application using asteroid but when I use Rocket.chat's LoadHistory method I get {isClientSafe: true, error: 400, reason: "Match failed", message: "Match failed [400]", errorType: "Meteor.Error"}. To be clear, I have never used Rocket.chat or Asteroid before. However some methods are working flawlessly.

/**
 * Calls a server-side method with the specified arguments.
 * @param method  string required: the name of the method to call
 * @param params  [param1, param2, ...] any optional: parameters passed to the 
   server method
 * @return Promise resolved, rejected
*/
let asteroidMethods = function (method, param){
  return socket.call(method, param)
};

getMessageHistory = (lastMessage) => {
  let param =[ lastMessage.rid, null, 50, lastMessage['ts']['$date']];
  asteroidMethods("loadHistory", param).then(res=>{
    console.log(res)
  }).catch(e=>{
    console.log(e)
  })
} 
1

There are 1 best solutions below

0
winterstefan On

Since the Match failed response is a rather generic one, there're several potential issues causing your error. For example, the lastMessage.rid could be empty.

With your problem, the Rocket.Chat server logs shall give you more information about the underlaying problem. For that, Rocket.Chat offers a nice way of accessing the server logs through the user interface:

Example

I've set my roomId to 42 in an example request:

connection.method('loadHistory', [42, roomId, oldestMessageDate, 15])

That triggers the following log event with very detailed information:

Exception while invoking method 'loadHistory'
{ Error: Match error: Expected string, got number }

With that information, you should be able to identify the actual issue behind your request.