Skip to content

Commit

Permalink
fix(web-console): keep table when 431 raised (#204)
Browse files Browse the repository at this point in the history
non-time out errors or server errors no longer remove table
  • Loading branch information
jerempy authored Oct 13, 2023
1 parent 461de07 commit 9846ef9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/web-console/src/scenes/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
VirtualList,
} from "../../components"
import { actions, selectors } from "../../store"
import { color, ErrorResult } from "../../utils"
import { color, ErrorResult, isServerError } from "../../utils"
import * as QuestDB from "../../utils/questdb"
import Table from "./Table"
import LoadingError from "./LoadingError"
Expand Down Expand Up @@ -192,7 +192,9 @@ const Schema = ({
}
},
(error) => {
setLoadingError(error)
if (isServerError(error)) {
setLoadingError(error)
}
},
() => {
setLoading(false)
Expand Down
1 change: 1 addition & 0 deletions packages/web-console/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
******************************************************************************/

export * from "./copyToClipboard"
export * from "./isServerError"
export * from "./fetch"
export * from "./fromFetch"
export * from "./questdb"
Expand Down
5 changes: 5 additions & 0 deletions packages/web-console/src/utils/isServerError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// isServerError takes api response and checks if the error is of type server error or timeout
// returns true if server error type
export const isServerError = (response: Response): boolean => {
return response.status === 408 || response.status >= 500;
};
21 changes: 12 additions & 9 deletions packages/web-console/src/utils/questdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* limitations under the License.
*
******************************************************************************/
import { isServerError } from "utils";
import { BusEvent } from "../consts"
import { TelemetryConfigShape } from "./../store/Telemetry/types"

Expand Down Expand Up @@ -77,6 +78,7 @@ type RawResult = RawDqlResult | RawDdlResult | RawErrorResult

export type ErrorResult = RawErrorResult & {
type: Type.ERROR
status: number
}

export type QueryRawResult =
Expand Down Expand Up @@ -328,17 +330,18 @@ export class Client {
}
}

const errorPayload = {
error: `QuestDB is not reachable [${response.status}]`,
position: -1,
query,
type: Type.ERROR,
const errorPayload: Record<string, string | number> = {
status: response.status,
error: response.statusText,
}

bus.trigger(BusEvent.MSG_CONNECTION_ERROR, {
...errorPayload,
status: response.status,
})
if (isServerError(response)) {
errorPayload.error = `QuestDB is not reachable [${response.status}]`;
errorPayload.position = -1;
errorPayload.query = query;
errorPayload.type = Type.ERROR;
bus.trigger(BusEvent.MSG_CONNECTION_ERROR, errorPayload)
}

// eslint-disable-next-line prefer-promise-reject-errors
return await Promise.reject(errorPayload)
Expand Down

0 comments on commit 9846ef9

Please sign in to comment.