mirror of https://github.com/apache/druid.git
fix task query error decode (#14174)
This commit is contained in:
parent
84c11df980
commit
98db960794
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import { sane } from 'druid-query-toolkit';
|
import { sane } from 'druid-query-toolkit';
|
||||||
|
|
||||||
import { DruidError, getDruidErrorMessage, parseHtmlError } from './druid-query';
|
import { DruidError, getDruidErrorMessage } from './druid-query';
|
||||||
|
|
||||||
describe('DruidQuery', () => {
|
describe('DruidQuery', () => {
|
||||||
describe('DruidError.parsePosition', () => {
|
describe('DruidError.parsePosition', () => {
|
||||||
|
@ -198,13 +198,41 @@ describe('DruidQuery', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('misc', () => {
|
describe('getDruidErrorMessage', () => {
|
||||||
it('parseHtmlError', () => {
|
it('works with regular error response', () => {
|
||||||
expect(parseHtmlError('<div></div>')).toMatchInlineSnapshot(`undefined`);
|
expect(
|
||||||
|
getDruidErrorMessage({
|
||||||
|
response: {
|
||||||
|
data: {
|
||||||
|
error: 'SQL parse failed',
|
||||||
|
errorMessage: 'Encountered "<EOF>" at line 1, column 26.\nWas expecting one of:...',
|
||||||
|
errorClass: 'org.apache.calcite.sql.parser.SqlParseException',
|
||||||
|
host: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toEqual(`SQL parse failed / Encountered "<EOF>" at line 1, column 26.
|
||||||
|
Was expecting one of:... / org.apache.calcite.sql.parser.SqlParseException`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parseHtmlError', () => {
|
it('works with task error response', () => {
|
||||||
expect(getDruidErrorMessage({})).toMatchInlineSnapshot(`undefined`);
|
expect(
|
||||||
|
getDruidErrorMessage({
|
||||||
|
response: {
|
||||||
|
data: {
|
||||||
|
taskId: '60a761ee-1ef5-437f-ae4c-adcc78c8a94c',
|
||||||
|
state: 'FAILED',
|
||||||
|
error: {
|
||||||
|
error: 'SQL parse failed',
|
||||||
|
errorMessage: 'Encountered "<EOF>" at line 1, column 26.\nWas expecting one of:...',
|
||||||
|
errorClass: 'org.apache.calcite.sql.parser.SqlParseException',
|
||||||
|
host: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toEqual(`SQL parse failed / Encountered "<EOF>" at line 1, column 26.
|
||||||
|
Was expecting one of:... / org.apache.calcite.sql.parser.SqlParseException`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,7 +54,10 @@ export function parseHtmlError(htmlStr: string): string | undefined {
|
||||||
function getDruidErrorObject(e: any): DruidErrorResponse | string {
|
function getDruidErrorObject(e: any): DruidErrorResponse | string {
|
||||||
if (e.response) {
|
if (e.response) {
|
||||||
// This is a direct axios response error
|
// This is a direct axios response error
|
||||||
return e.response.data || {};
|
let data = e.response.data || {};
|
||||||
|
// MSQ errors nest their error objects inside the error key. Yo dawg, I heard you like errors...
|
||||||
|
if (typeof data.error?.error === 'string') data = data.error;
|
||||||
|
return data;
|
||||||
} else {
|
} else {
|
||||||
return e; // Assume the error was passed in directly
|
return e; // Assume the error was passed in directly
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue