Skip to content

Commit 130ea77

Browse files
Merge remote-tracking branch 'origin/main' into beta-releases
2 parents b28152d + 70e22b2 commit 130ea77

File tree

132 files changed

+4038
-4516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+4038
-4516
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Tue Sep 19 2023.
2+
This document was automatically generated on Thu Sep 21 2023.
33

44
## List of dependencies
55

package-lock.json

Lines changed: 30 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/src/main.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe('AtlasServiceMain', function () {
299299
} catch (err) {
300300
expect(err).to.have.property(
301301
'message',
302-
'Error: too large of a request to send to the ai. Please use a smaller prompt or collection with smaller documents.'
302+
'Sorry, your request is too large. Please use a smaller prompt or try using this feature on a collection with smaller documents.'
303303
);
304304
}
305305
});
@@ -339,6 +339,7 @@ describe('AtlasServiceMain', function () {
339339
ok: false,
340340
status: 500,
341341
statusText: 'Internal Server Error',
342+
json: sandbox.stub().rejects(new Error('invalid json')),
342343
}) as any;
343344

344345
try {
@@ -349,7 +350,7 @@ describe('AtlasServiceMain', function () {
349350
});
350351
expect.fail(`Expected ${functionName} to throw`);
351352
} catch (err) {
352-
expect(err).to.have.property('message', '500 Internal Server Error');
353+
expect(err).to.have.property('message', '500: Internal Server Error');
353354
}
354355
});
355356
});
@@ -367,7 +368,7 @@ describe('AtlasServiceMain', function () {
367368
});
368369
});
369370

370-
it('should throw network error if res is not ok', async function () {
371+
it('should throw network error if res is not an atlas error', async function () {
371372
try {
372373
await throwIfNotOk({
373374
ok: false,
@@ -380,7 +381,7 @@ describe('AtlasServiceMain', function () {
380381
expect.fail('Expected throwIfNotOk to throw');
381382
} catch (err) {
382383
expect(err).to.have.property('name', 'NetworkError');
383-
expect(err).to.have.property('message', '500 Whoops');
384+
expect(err).to.have.property('message', '500: Whoops');
384385
}
385386
});
386387

@@ -402,6 +403,9 @@ describe('AtlasServiceMain', function () {
402403
} catch (err) {
403404
expect(err).to.have.property('name', 'ServerError');
404405
expect(err).to.have.property('message', 'ExampleCode: tortillas');
406+
expect(err).to.have.property('detail', 'tortillas');
407+
expect(err).to.have.property('errorCode', 'ExampleCode');
408+
expect(err).to.have.property('statusCode', 500);
405409
}
406410
});
407411
});

packages/atlas-service/src/main.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ipcMain, shell, app } from 'electron';
22
import { URL, URLSearchParams } from 'url';
33
import { createHash } from 'crypto';
44
import type { AuthFlowType, MongoDBOIDCPlugin } from '@mongodb-js/oidc-plugin';
5-
import type { AtlasServiceError } from './renderer';
5+
import { AtlasServiceError } from './util';
66
import {
77
createMongoDBOIDCPlugin,
88
hookLoggerToMongoLogWriter as oidcPluginHookLoggerToMongoLogWriter,
@@ -72,24 +72,22 @@ export async function throwIfNotOk(
7272
return;
7373
}
7474

75-
let serverErrorName = 'NetworkError';
76-
let serverErrorMessage = `${res.status} ${res.statusText}`;
77-
// We try to parse the response to see if the server returned any information
78-
// we can show a user.
79-
try {
80-
const messageJSON = await res.json();
81-
if (isServerError(messageJSON)) {
82-
serverErrorName = 'ServerError';
83-
serverErrorMessage = `${messageJSON.errorCode}: ${messageJSON.detail}`;
84-
}
85-
} catch (err) {
86-
// no-op, use the default status and statusText in the message.
75+
const messageJSON = await res.json().catch(() => undefined);
76+
if (messageJSON && isServerError(messageJSON)) {
77+
throw new AtlasServiceError(
78+
'ServerError',
79+
res.status,
80+
messageJSON.detail ?? 'Internal server error',
81+
messageJSON.errorCode ?? 'INTERNAL_SERVER_ERROR'
82+
);
83+
} else {
84+
throw new AtlasServiceError(
85+
'NetworkError',
86+
res.status,
87+
res.statusText,
88+
`${res.status}`
89+
);
8790
}
88-
89-
const err = new Error(serverErrorMessage);
90-
err.name = serverErrorName;
91-
(err as AtlasServiceError).statusCode = res.status;
92-
throw err;
9391
}
9492

9593
function throwIfAINotEnabled(atlasService: typeof AtlasService) {
@@ -639,7 +637,7 @@ export class AtlasService {
639637
});
640638
if (msgBody.length > AI_MAX_REQUEST_SIZE) {
641639
throw new Error(
642-
'Error: too large of a request to send to the ai. Please use a smaller prompt or collection with smaller documents.'
640+
'Sorry, your request is too large. Please use a smaller prompt or try using this feature on a collection with smaller documents.'
643641
);
644642
}
645643
}
@@ -651,7 +649,13 @@ export class AtlasService {
651649
mongoLogId(1_001_000_247),
652650
'AtlasService',
653651
'Running aggregation generation request',
654-
{ url, body: msgBody }
652+
{
653+
url,
654+
userInput,
655+
collectionName,
656+
databaseName,
657+
messageBodyLength: msgBody.length,
658+
}
655659
);
656660

657661
const res = await this.fetch(url, {
@@ -720,7 +724,7 @@ export class AtlasService {
720724
});
721725
if (msgBody.length > AI_MAX_REQUEST_SIZE) {
722726
throw new Error(
723-
'Error: too large of a request to send to the ai. Please use a smaller prompt or collection with smaller documents.'
727+
'Sorry, your request is too large. Please use a smaller prompt or try using this feature on a collection with smaller documents.'
724728
);
725729
}
726730
}
@@ -732,7 +736,13 @@ export class AtlasService {
732736
mongoLogId(1_001_000_249),
733737
'AtlasService',
734738
'Running query generation request',
735-
{ url, body: msgBody }
739+
{
740+
url,
741+
userInput,
742+
collectionName,
743+
databaseName,
744+
messageBodyLength: msgBody.length,
745+
}
736746
);
737747

738748
const res = await this.fetch(url, {

packages/atlas-service/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ export class AtlasService {
146146

147147
export { AtlasSignIn } from './components/atlas-signin';
148148

149+
export { AtlasServiceError } from './util';
149150
export type {
150151
AtlasUserInfo,
151152
AtlasUserConfig,
152153
IntrospectInfo,
153154
Token,
154-
AtlasServiceError,
155155
AIQuery,
156156
AIAggregation,
157157
} from './util';

0 commit comments

Comments
 (0)