File tree Expand file tree Collapse file tree 2 files changed +11
-21
lines changed
x-pack/plugins/ingest_manager/server Expand file tree Collapse file tree 2 files changed +11
-21
lines changed Original file line number Diff line number Diff line change 44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7+ /* eslint-disable max-classes-per-file */
78export class IngestManagerError extends Error {
8- public type : IngestManagerErrorType ;
9- public message : string ;
10-
11- constructor ( type : IngestManagerErrorType , message : string ) {
9+ constructor ( message ?: string ) {
1210 super ( message ) ;
13- this . type = type ;
14- this . message = message ;
11+ this . name = this . constructor . name ; // for stack traces
1512 }
1613}
1714
1815export const getHTTPResponseCode = ( error : IngestManagerError ) : number => {
19- switch ( error . type ) {
20- case IngestManagerErrorType . RegistryError :
21- return 502 ; // Bad Gateway
22- default :
23- return 400 ; // Bad Request
16+ if ( error instanceof RegistryError ) {
17+ return 502 ; // Bad Gateway
18+ } else {
19+ return 400 ; // Bad Request
2420 }
2521} ;
2622
27- export enum IngestManagerErrorType {
28- RegistryError ,
29- }
23+ export class RegistryError extends IngestManagerError { }
Original file line number Diff line number Diff line change 66
77import fetch , { Response } from 'node-fetch' ;
88import { streamToString } from './streams' ;
9- import { IngestManagerError , IngestManagerErrorType } from '../../../errors' ;
9+ import { RegistryError } from '../../../errors' ;
1010
1111export async function getResponse ( url : string ) : Promise < Response > {
1212 try {
1313 const response = await fetch ( url ) ;
1414 if ( response . ok ) {
1515 return response ;
1616 } else {
17- throw new IngestManagerError (
18- IngestManagerErrorType . RegistryError ,
17+ throw new RegistryError (
1918 `Error connecting to package registry at ${ url } : ${ response . statusText } `
2019 ) ;
2120 }
2221 } catch ( e ) {
23- throw new IngestManagerError (
24- IngestManagerErrorType . RegistryError ,
25- `Error connecting to package registry at ${ url } : ${ e . message } `
26- ) ;
22+ throw new RegistryError ( `Error connecting to package registry at ${ url } : ${ e . message } ` ) ;
2723 }
2824}
2925
You can’t perform that action at this time.
0 commit comments