mirror of
				https://github.com/Azure/cosmos-explorer.git
				synced 2025-10-30 22:50:32 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									8200cc521f
								
							
						
					
					
						commit
						dd199e6565
					
				| @ -26,7 +26,6 @@ src/Common/Logger.test.ts | |||||||
| src/Common/MessageHandler.test.ts | src/Common/MessageHandler.test.ts | ||||||
| src/Common/MessageHandler.ts | src/Common/MessageHandler.ts | ||||||
| src/Common/MongoProxyClient.test.ts | src/Common/MongoProxyClient.test.ts | ||||||
| src/Common/MongoProxyClient.ts |  | ||||||
| src/Common/MongoUtility.ts | src/Common/MongoUtility.ts | ||||||
| src/Common/NotificationsClientBase.ts | src/Common/NotificationsClientBase.ts | ||||||
| src/Common/ObjectCache.test.ts | src/Common/ObjectCache.test.ts | ||||||
|  | |||||||
| @ -31,13 +31,13 @@ function authHeaders(): any { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function queryIterator(databaseId: string, collection: Collection, query: string) { | export function queryIterator(databaseId: string, collection: Collection, query: string): any { | ||||||
|   let continuationToken: string = null; |   let continuationToken: string; | ||||||
|   return { |   return { | ||||||
|     fetchNext: () => { |     fetchNext: () => { | ||||||
|       return queryDocuments(databaseId, collection, false, query).then(response => { |       return queryDocuments(databaseId, collection, false, query).then(response => { | ||||||
|         continuationToken = response.continuationToken; |         continuationToken = response.continuationToken; | ||||||
|         let headers = {} as any; |         const headers = {} as any; | ||||||
|         response.headers.forEach((value: any, key: any) => { |         response.headers.forEach((value: any, key: any) => { | ||||||
|           headers[key] = value; |           headers[key] = value; | ||||||
|         }); |         }); | ||||||
| @ -114,14 +114,7 @@ export function queryDocuments( | |||||||
|           headers: response.headers |           headers: response.headers | ||||||
|         }; |         }; | ||||||
|       } |       } | ||||||
|       const errorMessage = await response.text(); |       return errorHandling(response, "querying documents", params); | ||||||
|       if (response.status === HttpStatusCodes.Forbidden) { |  | ||||||
|         MessageHandler.sendMessage({ |  | ||||||
|           type: MessageTypes.ForbiddenError, |  | ||||||
|           reason: errorMessage |  | ||||||
|         }); |  | ||||||
|       } |  | ||||||
|       throw new Error(errorMessage); |  | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -160,11 +153,11 @@ export function readDocument( | |||||||
|         ) |         ) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     .then(async response => { |     .then(response => { | ||||||
|       if (response.ok) { |       if (response.ok) { | ||||||
|         return response.json(); |         return response.json(); | ||||||
|       } |       } | ||||||
|       errorHandling(response); |       return errorHandling(response, "reading document", params); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -199,11 +192,11 @@ export function createDocument( | |||||||
|         ...authHeaders() |         ...authHeaders() | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     .then(async response => { |     .then(response => { | ||||||
|       if (response.ok) { |       if (response.ok) { | ||||||
|         return response.json(); |         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()) |         [CosmosSDKConstants.HttpHeaders.PartitionKey]: JSON.stringify(documentId.partitionKeyHeader()) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     .then(async response => { |     .then(response => { | ||||||
|       if (response.ok) { |       if (response.ok) { | ||||||
|         return response.json(); |         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()) |         [CosmosSDKConstants.HttpHeaders.PartitionKey]: JSON.stringify(documentId.partitionKeyHeader()) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     .then(async response => { |     .then(response => { | ||||||
|       if (response.ok) { |       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) { |       if (response.ok) { | ||||||
|         return; |         return undefined; | ||||||
|       } |       } | ||||||
|       NotificationConsoleUtils.logConsoleMessage( |       return errorHandling(response, "creating collection", params); | ||||||
|         ConsoleDataType.Error, |  | ||||||
|         `Error creating collection: ${await response.json()}, Payload: ${params}` |  | ||||||
|       ); |  | ||||||
|       errorHandling(response); |  | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -407,13 +396,16 @@ export function getEndpoint(databaseAccount: ViewModels.DatabaseAccount): string | |||||||
|   return url; |   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(); |   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) { |   if (response.status === HttpStatusCodes.Forbidden) { | ||||||
|     MessageHandler.sendMessage({ |     MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError, reason: errorMessage }); | ||||||
|       type: MessageTypes.ForbiddenError, |     return; | ||||||
|       reason: errorMessage |  | ||||||
|     }); |  | ||||||
|   } |   } | ||||||
|   throw new Error(errorMessage); |   throw new Error(errorMessage); | ||||||
| } | } | ||||||
| @ -462,14 +454,6 @@ export async function _createMongoCollectionWithARM( | |||||||
|       rpPayloadToCreateCollection |       rpPayloadToCreateCollection | ||||||
|     ); |     ); | ||||||
|   } catch (response) { |   } catch (response) { | ||||||
|     NotificationConsoleUtils.logConsoleMessage( |     return errorHandling(response, "creating collection", undefined); | ||||||
|       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`); |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -177,10 +177,9 @@ export default class MongoDocumentsTab extends DocumentsTab implements ViewModel | |||||||
|           ); |           ); | ||||||
|         }, |         }, | ||||||
|         reason => { |         reason => { | ||||||
|  |           this.isExecutionError(true); | ||||||
|           const message = ErrorParserUtility.parse(reason)[0].message; |           const message = ErrorParserUtility.parse(reason)[0].message; | ||||||
|           window.alert(message); |           window.alert(message); | ||||||
|           this.isExecutionError(true); |  | ||||||
|           console.error(reason); |  | ||||||
|           TelemetryProcessor.traceFailure( |           TelemetryProcessor.traceFailure( | ||||||
|             Action.UpdateDocument, |             Action.UpdateDocument, | ||||||
|             { |             { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user