Skip to content

Commit

Permalink
Extend Error and simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed May 25, 2020
1 parent e4795b9 commit 4719bdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 5 additions & 12 deletions x-pack/plugins/ingest_manager/server/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

export class IngestManagerError {
private type: IngestManagerErrorType;
private message: string;
export class IngestManagerError extends Error {
public type: IngestManagerErrorType;
public message: string;

constructor(type: IngestManagerErrorType, message: string) {
super(message);
this.type = type;
this.message = message;
}

public getType = (): IngestManagerErrorType => {
return this.type;
};

public getMessage = (): string => {
return this.message;
};
}

export const getHTTPResponseCode = (error: IngestManagerError): number => {
switch (error.getType()) {
switch (error.type) {
case IngestManagerErrorType.RegistryError:
return 502; // Bad Gateway
default:
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/server/routes/setup/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export const ingestManagerSetupHandler: RequestHandler = async (context, request
});
} catch (e) {
if (e instanceof IngestManagerError) {
logger.error(e.getMessage());
logger.error(e.message);
return response.customError({
statusCode: getHTTPResponseCode(e),
body: { message: e.getMessage() },
body: { message: e.message },
});
}
if (e.isBoom) {
Expand Down

0 comments on commit 4719bdb

Please sign in to comment.