Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
56dd7fcb
Unverified
Commit
56dd7fcb
authored
Feb 02, 2021
by
Chris Cowan
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elasticsearch: Display errors with text responses (#30122)
Co-authored-by: Elfo404 <gio.ricci@grafana.com>
parent
64254eaa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
public/app/plugins/datasource/elasticsearch/datasource.test.ts
+31
-0
public/app/plugins/datasource/elasticsearch/datasource.ts
+4
-2
No files found.
public/app/plugins/datasource/elasticsearch/datasource.test.ts
View file @
56dd7fcb
...
...
@@ -345,6 +345,37 @@ describe('ElasticDatasource', function (this: any) {
});
});
it
(
'should properly throw an error with just a message'
,
async
()
=>
{
const
response
:
FetchResponse
=
{
data
:
{
error
:
'Bad Request'
,
message
:
'Authentication to data source failed'
,
},
status
:
400
,
url
:
'http://localhost:3000/api/tsdb/query'
,
config
:
{
url
:
'http://localhost:3000/api/tsdb/query'
},
type
:
'basic'
,
statusText
:
'Bad Request'
,
redirected
:
false
,
headers
:
({}
as
unknown
)
as
Headers
,
ok
:
false
,
};
const
{
ds
}
=
getTestContext
({
mockImplementation
:
()
=>
throwError
(
response
),
});
const
errObject
=
{
error
:
'Bad Request'
,
message
:
'Elasticsearch error: Authentication to data source failed'
,
};
await
expect
(
ds
.
query
(
query
)).
toEmitValuesWith
((
received
)
=>
{
expect
(
received
.
length
).
toBe
(
1
);
expect
(
received
[
0
]).
toEqual
(
errObject
);
});
});
it
(
'should properly throw an unknown error'
,
async
()
=>
{
const
{
ds
}
=
getTestContext
({
jsonData
:
{
interval
:
'Daily'
,
esVersion
:
7
},
...
...
public/app/plugins/datasource/elasticsearch/datasource.ts
View file @
56dd7fcb
...
...
@@ -127,9 +127,11 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
return
results
.
data
;
}),
catchError
((
err
)
=>
{
if
(
err
.
data
&&
err
.
data
.
error
)
{
if
(
err
.
data
)
{
const
message
=
err
.
data
.
error
?.
reason
??
err
.
data
.
message
??
'Unknown error'
;
return
throwError
({
message
:
'Elasticsearch error: '
+
err
.
data
.
error
.
reason
,
message
:
'Elasticsearch error: '
+
message
,
error
:
err
.
data
.
error
,
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment