File tree Expand file tree Collapse file tree 2 files changed +3
-41
lines changed Expand file tree Collapse file tree 2 files changed +3
-41
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import * as fs from 'fs' ;
22import * as api from '@gitbook/api' ;
33import { getAPIClient } from '../remote' ;
4- import { logger } from '../logger' ;
54
65/**
76 * Publish an OpenAPI specification to GitBook from a URL.
@@ -69,35 +68,31 @@ async function readOpenAPIFile(filePath: string): Promise<string> {
6968 return fileContent ;
7069 } catch ( error ) {
7170 if ( error instanceof Error && 'code' in error && error . code === 'ENOENT' ) {
72- logger . error ( `OpenAPI specification file not found: ${ filePath } ` ) ;
73- process . exit ( 1 ) ;
71+ throw new Error ( `OpenAPI specification file not found: ${ filePath } ` ) ;
7472 }
7573 throw error ;
7674 }
7775}
7876
79-
8077const OPENAPISPEC_SLUG_REGEX = new RegExp ( api . OPEN_APISPEC_SLUG_PATTERN ) ;
8178/**
8279 * Validate the OpenAPI specification slug.
8380 * It should match the pattern and be between the minimum and maximum length.
8481 */
8582function validateSlug ( specSlug : string ) {
8683 if ( ! OPENAPISPEC_SLUG_REGEX . test ( specSlug ) ) {
87- logger . error (
84+ throw new Error (
8885 `Invalid OpenAPI specification slug, must match pattern: ${ api . OPEN_APISPEC_SLUG_PATTERN } ` ,
8986 ) ;
90- process . exit ( 1 ) ;
9187 }
9288
9389 if (
9490 specSlug . length < api . OPEN_APISPEC_SLUG_MIN_LENGTH ||
9591 specSlug . length > api . OPEN_APISPEC_SLUG_MAX_LENGTH
9692 ) {
97- logger . error (
93+ throw new Error (
9894 `Invalid OpenAPI specification slug, must be between ${ api . OPEN_APISPEC_SLUG_MIN_LENGTH } and ${ api . OPEN_APISPEC_SLUG_MAX_LENGTH } characters` ,
9995 ) ;
100- process . exit ( 1 ) ;
10196 }
10297
10398 return specSlug ;
You can’t perform that action at this time.
0 commit comments