From 19f272ca92e2a2c3d1e99eb5e7c3a3f0ef04175d Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 13 Aug 2020 11:01:47 +0300 Subject: [PATCH] feat: handle redirects in api definition request --- npm/ng-packs/packages/schematics/src/utils/source.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/utils/source.ts b/npm/ng-packs/packages/schematics/src/utils/source.ts index 81d0b287fe..b1411b6bca 100644 --- a/npm/ng-packs/packages/schematics/src/utils/source.ts +++ b/npm/ng-packs/packages/schematics/src/utils/source.ts @@ -14,8 +14,14 @@ export async function getSourceJson(url: string) { searchParams: { includeTypes: true }, https: { rejectUnauthorized: false }, })); - } catch (e) { - throw new SchematicsException(Exception.NoApi); + } catch (err) { + // handle redirects + try { + ({ response: { body } } = err); + if (!body.types) throw Error(''); + } catch (_) { + throw new SchematicsException(Exception.NoApi); + } } return body;