fix task query error decode (#14174)

This commit is contained in:
Vadim Ogievetsky 2023-04-27 15:26:07 -07:00 committed by GitHub
parent 84c11df980
commit 98db960794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 7 deletions

View File

@ -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`);
}); });
}); });
}); });

View File

@ -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
} }