Fixing errors in mongo document tab (#58)

* This fixes an issue where errors when editing documents in an API for MongoDB endpoint would not be presented in the UI.

* Changing null to undefined in several places

* Fixed style issue.
Unignored MongoProxyClient.ts from full lint

* More linter issues since the removal from lint ignore
This commit is contained in:
vchske 2020-06-29 16:02:31 -07:00 committed by GitHub
parent 8200cc521f
commit dd199e6565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 44 deletions

View File

@ -26,7 +26,6 @@ src/Common/Logger.test.ts
src/Common/MessageHandler.test.ts
src/Common/MessageHandler.ts
src/Common/MongoProxyClient.test.ts
src/Common/MongoProxyClient.ts
src/Common/MongoUtility.ts
src/Common/NotificationsClientBase.ts
src/Common/ObjectCache.test.ts

View File

@ -31,13 +31,13 @@ function authHeaders(): any {
}
}
export function queryIterator(databaseId: string, collection: Collection, query: string) {
let continuationToken: string = null;
export function queryIterator(databaseId: string, collection: Collection, query: string): any {
let continuationToken: string;
return {
fetchNext: () => {
return queryDocuments(databaseId, collection, false, query).then(response => {
continuationToken = response.continuationToken;
let headers = {} as any;
const headers = {} as any;
response.headers.forEach((value: any, key: any) => {
headers[key] = value;
});
@ -114,14 +114,7 @@ export function queryDocuments(
headers: response.headers
};
}
const errorMessage = await response.text();
if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({
type: MessageTypes.ForbiddenError,
reason: errorMessage
});
}
throw new Error(errorMessage);
return errorHandling(response, "querying documents", params);
});
}
@ -160,11 +153,11 @@ export function readDocument(
)
}
})
.then(async response => {
.then(response => {
if (response.ok) {
return response.json();
}
errorHandling(response);
return errorHandling(response, "reading document", params);
});
}
@ -199,11 +192,11 @@ export function createDocument(
...authHeaders()
}
})
.then(async response => {
.then(response => {
if (response.ok) {
return response.json();
}
errorHandling(response);
return errorHandling(response, "creating document", params);
});
}
@ -243,11 +236,11 @@ export function updateDocument(
[CosmosSDKConstants.HttpHeaders.PartitionKey]: JSON.stringify(documentId.partitionKeyHeader())
}
})
.then(async response => {
.then(response => {
if (response.ok) {
return response.json();
}
errorHandling(response);
return errorHandling(response, "updating document", params);
});
}
@ -285,11 +278,11 @@ export function deleteDocument(
[CosmosSDKConstants.HttpHeaders.PartitionKey]: JSON.stringify(documentId.partitionKeyHeader())
}
})
.then(async response => {
.then(response => {
if (response.ok) {
return;
return undefined;
}
errorHandling(response);
return errorHandling(response, "deleting document", params);
});
}
@ -340,15 +333,11 @@ export function createMongoCollectionWithProxy(
}
}
)
.then(async response => {
.then(response => {
if (response.ok) {
return;
return undefined;
}
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error creating collection: ${await response.json()}, Payload: ${params}`
);
errorHandling(response);
return errorHandling(response, "creating collection", params);
});
}
@ -407,13 +396,16 @@ export function getEndpoint(databaseAccount: ViewModels.DatabaseAccount): string
return url;
}
async function errorHandling(response: any): Promise<any> {
async function errorHandling(response: any, action: string, params: any): Promise<any> {
const errorMessage = await response.text();
// Log the error where the user can see it
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error ${action}: ${errorMessage}, Payload: ${JSON.stringify(params)}`
);
if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({
type: MessageTypes.ForbiddenError,
reason: errorMessage
});
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError, reason: errorMessage });
return;
}
throw new Error(errorMessage);
}
@ -462,14 +454,6 @@ export async function _createMongoCollectionWithARM(
rpPayloadToCreateCollection
);
} catch (response) {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error creating collection: ${JSON.stringify(response)}`
);
if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError });
return;
}
throw new Error(`Error creating collection`);
return errorHandling(response, "creating collection", undefined);
}
}

View File

@ -177,10 +177,9 @@ export default class MongoDocumentsTab extends DocumentsTab implements ViewModel
);
},
reason => {
this.isExecutionError(true);
const message = ErrorParserUtility.parse(reason)[0].message;
window.alert(message);
this.isExecutionError(true);
console.error(reason);
TelemetryProcessor.traceFailure(
Action.UpdateDocument,
{