Skip to content

Commit 4719bdb

Browse files
committed
Extend Error and simplify.
1 parent e4795b9 commit 4719bdb

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

x-pack/plugins/ingest_manager/server/errors.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export class IngestManagerError {
8-
private type: IngestManagerErrorType;
9-
private message: string;
7+
export class IngestManagerError extends Error {
8+
public type: IngestManagerErrorType;
9+
public message: string;
1010

1111
constructor(type: IngestManagerErrorType, message: string) {
12+
super(message);
1213
this.type = type;
1314
this.message = message;
1415
}
15-
16-
public getType = (): IngestManagerErrorType => {
17-
return this.type;
18-
};
19-
20-
public getMessage = (): string => {
21-
return this.message;
22-
};
2316
}
2417

2518
export const getHTTPResponseCode = (error: IngestManagerError): number => {
26-
switch (error.getType()) {
19+
switch (error.type) {
2720
case IngestManagerErrorType.RegistryError:
2821
return 502; // Bad Gateway
2922
default:

x-pack/plugins/ingest_manager/server/routes/setup/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export const ingestManagerSetupHandler: RequestHandler = async (context, request
8383
});
8484
} catch (e) {
8585
if (e instanceof IngestManagerError) {
86-
logger.error(e.getMessage());
86+
logger.error(e.message);
8787
return response.customError({
8888
statusCode: getHTTPResponseCode(e),
89-
body: { message: e.getMessage() },
89+
body: { message: e.message },
9090
});
9191
}
9292
if (e.isBoom) {

0 commit comments

Comments
 (0)