forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDS] Use DataSourceError to replace Error in getDataSourceById call (o…
…pensearch-project#6903) * Use DataSourceError to replace Error in getDataSourceById call Signed-off-by: yujin-emma <[email protected]> * Relocate the DataSourceError to make it can be used cross plugin folder Signed-off-by: yujin-emma <[email protected]> * add the missing bundles Signed-off-by: yujin-emma <[email protected]> * Fix failed integration test Signed-off-by: yujin-emma <[email protected]> --------- Signed-off-by: yujin-emma <[email protected]> Co-authored-by: Lu Yu <[email protected]> Co-authored-by: ZilongX <[email protected]>
- Loading branch information
1 parent
9674147
commit fbb8973
Showing
12 changed files
with
90 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ResponseError } from '@opensearch-project/opensearch/lib/errors'; | ||
import { OsdError } from '../../../opensearch_dashboards_utils/common'; | ||
|
||
export class DataSourceError extends OsdError { | ||
// must have statusCode to avoid route handler in search.ts to return 500 | ||
statusCode: number; | ||
body: any; | ||
|
||
constructor(error: any, context?: string, statusCode?: number) { | ||
let message: string; | ||
if (context) { | ||
message = context; | ||
} else if (isResponseError(error)) { | ||
message = JSON.stringify(error.meta.body); | ||
} else { | ||
message = error.message; | ||
} | ||
|
||
super('Data Source Error: ' + message); | ||
|
||
if (error.body) { | ||
this.body = error.body; | ||
} | ||
|
||
if (statusCode) { | ||
this.statusCode = statusCode; | ||
} else if (error.statusCode) { | ||
this.statusCode = error.statusCode; | ||
} else { | ||
this.statusCode = 400; | ||
} | ||
} | ||
} | ||
|
||
export const isResponseError = (error: any): error is ResponseError => { | ||
return Boolean(error.body && error.statusCode && error.headers); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters