From 73fa2e19e45ef2a89cad16996b7158645b5a18e5 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Thu, 10 Apr 2025 18:26:29 +0545 Subject: [PATCH] fix: enhance error handling for unsupported Postman schema versions and invalid JSON format --- .../src/postman/postman-to-bruno.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/bruno-converters/src/postman/postman-to-bruno.js b/packages/bruno-converters/src/postman/postman-to-bruno.js index 1f61045d4..8ab9e9917 100644 --- a/packages/bruno-converters/src/postman/postman-to-bruno.js +++ b/packages/bruno-converters/src/postman/postman-to-bruno.js @@ -310,8 +310,8 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => { } else { if (i.request) { - if(!requestMethods.includes(i?.request?.method.toUpperCase())){ - console.warn("Unexpected request.method") + if (!requestMethods.includes(i?.request?.method.toUpperCase())) { + console.warn('Unexpected request.method', i?.request?.method); return; } @@ -589,28 +589,28 @@ const parsePostmanCollection = (collection) => { return importPostmanV2Collection(collection); } - throw new Error('Unknown postman schema'); + throw new Error('Unsupported Postman schema version. Only Postman Collection v2.0 and v2.1 are supported.'); } catch (err) { console.log(err); if (err instanceof Error) { throw err; } - throw new Error('Unable to parse the postman collection json file'); + throw new Error('Invalid Postman collection format. Please check your JSON file.'); } }; const postmanToBruno = (postmanCollection) => { - try { - const parsedPostmanCollection = parsePostmanCollection(postmanCollection); - const transformedCollection = transformItemsInCollection(parsedPostmanCollection); - const hydratedCollection = hydrateSeqInCollection(transformedCollection); - const validatedCollection = validateSchema(hydratedCollection); - return validatedCollection; - } catch(err) { - console.log(err); - throw new Error('Import collection failed'); - } + try { + const parsedPostmanCollection = parsePostmanCollection(postmanCollection); + const transformedCollection = transformItemsInCollection(parsedPostmanCollection); + const hydratedCollection = hydrateSeqInCollection(transformedCollection); + const validatedCollection = validateSchema(hydratedCollection); + return validatedCollection; + } catch (err) { + console.log(err); + throw new Error(`Import collection failed: ${err.message}`); + } }; export default postmanToBruno; \ No newline at end of file