Matrix-js-SDK MatrixError: [405] Unrecognized request
maxine-96 opened this issue · 5 comments
Hey,
I am reaching out to seek assistance with an issue I am encountering while using the Matrix client.
The problem arises when I call the client.joinRoom(roomId) function. It seems that an additional "/?" is appended to the URL, causing the request to fail with a "405 Unrecognized request" error.
The client already exists and the credentials are set correctly. :)
SDK Version 32.0.0
Here are the relevant log entries:
DEBUG FetchHttpApi: <-- POST ?? [92ms 405]
DEBUG FetchHttpApi: <-- POST ?? [90ms 405]
ERROR Error creating room: [M_UNRECOGNIZED: MatrixError: [405] Unrecognized request (https://my-matrix-server/_matrix/client/v3/createRoom/?)]
ERROR Error joining room: [M_UNRECOGNIZED: MatrixError: [405] Unrecognized request (https://my-matrix-server/_matrix/client/v3/join/!ibNGtYzOqOyFMbTGaO%3Amy-matrix-server/?)]
My react native code:
useEffect(() => {
const initMatrixClient = async () => {
try {
const credentials = await getMatrixCredentials();
const matrixClient = createClient({
baseUrl: BASIC_MATRIX_URL,
accessToken: credentials?.accessToken,
deviceId: credentials?.deviceId,
userId: credentials?.userId,
});
setClient(matrixClient);
} catch (error) {
console.log(error)
throw new Error(error);
}
};
initMatrixClient();
}, []);
useEffect(() => {
if (client) {
joinRoom(client)
}
}, [client]);
async function joinRoom(client: MatrixClient): Promise<void> {
console.log(client)
try {
await client.joinRoom(currentRoomId);
} catch (error) {
console.error(`Error: ${error}`);
}
}
I don't see anything in the code base that would append /?
. I suggest sharing a minimum reproduction case rather than a subset of one. My guess is whatever fetch polyfill you are using is doing this.
Closing due to lack of info
Actually I have the same problem - /?
is appended to the end of every request which makes them to fail. I'm using react-native mobile app with matrix-js-sdk
integrated with some polyfills. I guess I might need to check if those polyfills add /?
somehow...
Okay it turns out my client was not using react-native-url-polyfill
, so after adding it and applying it by adding import 'react-native-url-polyfill/auto';
now it works :)
@maxine-96 hopefully it helps ^^^