Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging of queries in ra-data-fakerest #9960

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/ra-data-fakerest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,27 @@ export default (data, loggingEnabled = false, delay?: number): DataProvider => {
* @param {Object} params The data request params, depending on the type
* @returns {Promise} The response
*/
const handle = (type, resource, params): Promise<any> => {
const handle = async (type, resource, params): Promise<any> => {
const collection = database.getCollection(resource);
if (!collection && type !== 'create') {
const error = new UndefinedResourceError(
`Undefined collection "${resource}"`
);
error.code = 1; // make that error detectable
return Promise.reject(error);
throw error;
}
let response;
try {
response = getResponse(type, resource, params);
response = await getResponse(type, resource, params);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the root cause: since the introduction of the delay in #9908, getResponse may return a Promise.

} catch (error) {
console.error(error);
return Promise.reject(error);
throw error;
}
if (loggingEnabled) {
const { signal, ...paramsWithoutSignal } = params;
log(type, resource, paramsWithoutSignal, response);
}
return Promise.resolve(response);
return response;
};

return {
Expand Down
Loading