-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MD]Improve datasource error handling
Signed-off-by: Su <[email protected]>
- Loading branch information
1 parent
7fefb05
commit cb5a74c
Showing
5 changed files
with
66 additions
and
49 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
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,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; | ||
import { OsdError } from '../../../../../src/plugins/opensearch_dashboards_utils/common'; | ||
|
||
export class DataSourceConfigError extends OsdError { | ||
// must have statusCode to avoid route handler in search.ts to return 500 | ||
statusCode: number; | ||
constructor(messagePrefix: string, error: any) { | ||
const messageContent = SavedObjectsErrorHelpers.isSavedObjectsClientError(error) | ||
? error.output.payload.message | ||
: error.message; | ||
super(messagePrefix + messageContent); | ||
// Cast all 5xx error returned by saveObjectClient to 500, 400 for both savedObject client | ||
// 4xx errors, and other errors | ||
this.statusCode = SavedObjectsErrorHelpers.isOpenSearchUnavailableError(error) ? 500 : 400; | ||
} | ||
} |
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