-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] fix error construction and retrieving status (#8807)
Signed-off-by: Joshua Li <[email protected]>
- Loading branch information
1 parent
4f6b287
commit 016f090
Showing
3 changed files
with
30 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { handleFacetError } from './utils'; | ||
|
||
describe('handleFacetError', () => { | ||
const error = new Error('mock-error'); | ||
(error as any).body = { | ||
message: 'test error message', | ||
}; | ||
(error as any).status = '400'; | ||
it('should throw an error with message from response.data.body.message', () => { | ||
const response = { | ||
data: error, | ||
}; | ||
|
||
expect(() => handleFacetError(response)).toThrowError(); | ||
try { | ||
handleFacetError(response); | ||
} catch (err: any) { | ||
expect(err.message).toBe('test error message'); | ||
expect(err.name).toBe('400'); | ||
expect(err.status).toBe('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
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