Skip to content

Commit 9de6999

Browse files
authoredApr 7, 2025··
perf: Add details to error message in Parse.Query.aggregate (#9689)
1 parent 9d8d494 commit 9de6999

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed
 

‎spec/ParseQuery.Aggregate.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -1500,4 +1500,24 @@ describe('Parse.Query Aggregate testing', () => {
15001500
expect(results.length).toEqual(3);
15011501
await database.adapter.deleteAllClasses(false);
15021502
});
1503+
1504+
it_only_db('mongo')('aggregate handle mongodb errors', async () => {
1505+
const pipeline = [
1506+
{
1507+
$search: {
1508+
index: "default",
1509+
text: {
1510+
path: ["name"],
1511+
query: 'foo',
1512+
},
1513+
},
1514+
},
1515+
];
1516+
try {
1517+
await new Parse.Query(TestObject).aggregate(pipeline);
1518+
fail();
1519+
} catch (e) {
1520+
expect(e.code).toBe(Parse.Error.INVALID_QUERY);
1521+
}
1522+
});
15031523
});

‎spec/support/CurrentSpecReporter.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const flakyTests = [
2222
"Email Verification Token Expiration: sets the _email_verify_token_expires_at and _email_verify_token fields after user SignUp",
2323
// Expected 0 to be 1.
2424
"Email Verification Token Expiration: should send a new verification email when a resend is requested and the user is UNVERIFIED",
25+
// Expected 0 to be 1.
26+
"Email Verification Token Expiration: should match codes with emailVerifyTokenReuseIfValid",
2527
];
2628

2729
/** The minimum execution time in seconds for a test to be considered slow. */

‎src/Routers/AggregateRouter.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ClassesRouter from './ClassesRouter';
55
import UsersRouter from './UsersRouter';
66

77
export class AggregateRouter extends ClassesRouter {
8-
handleFind(req) {
8+
async handleFind(req) {
99
const body = Object.assign(req.body || {}, ClassesRouter.JSONFromQuery(req.query));
1010
const options = {};
1111
if (body.distinct) {
@@ -31,24 +31,25 @@ export class AggregateRouter extends ClassesRouter {
3131
if (typeof body.where === 'string') {
3232
body.where = JSON.parse(body.where);
3333
}
34-
return rest
35-
.find(
34+
try {
35+
const response = await rest.find(
3636
req.config,
3737
req.auth,
3838
this.className(req),
3939
body.where,
4040
options,
4141
req.info.clientSDK,
4242
req.info.context
43-
)
44-
.then(response => {
45-
for (const result of response.results) {
46-
if (typeof result === 'object') {
47-
UsersRouter.removeHiddenProperties(result);
48-
}
43+
);
44+
for (const result of response.results) {
45+
if (typeof result === 'object') {
46+
UsersRouter.removeHiddenProperties(result);
4947
}
50-
return { response };
51-
});
48+
}
49+
return { response };
50+
} catch (e) {
51+
throw new Parse.Error(Parse.Error.INVALID_QUERY, e.message);
52+
}
5253
}
5354

5455
/* Builds a pipeline from the body. Originally the body could be passed as a single object,

0 commit comments

Comments
 (0)
Please sign in to comment.