servers/
error.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::any::Any;
16use std::net::SocketAddr;
17use std::string::FromUtf8Error;
18
19use axum::http::StatusCode as HttpStatusCode;
20use axum::response::{IntoResponse, Response};
21use axum::{Json, http};
22use base64::DecodeError;
23use common_base::readable_size::ReadableSize;
24use common_error::define_into_tonic_status;
25use common_error::ext::{BoxedError, ErrorExt};
26use common_error::status_code::StatusCode;
27use common_macro::stack_trace_debug;
28use common_telemetry::{error, warn};
29use common_time::Duration;
30use datafusion::error::DataFusionError;
31use datatypes::prelude::ConcreteDataType;
32use headers::ContentType;
33use http::header::InvalidHeaderValue;
34use query::parser::PromQuery;
35use serde_json::json;
36use snafu::{Location, Snafu};
37
38#[derive(Snafu)]
39#[snafu(visibility(pub))]
40#[stack_trace_debug]
41pub enum Error {
42    #[snafu(display("Failed to bind address: {}", addr))]
43    AddressBind {
44        addr: SocketAddr,
45        #[snafu(source)]
46        error: std::io::Error,
47        #[snafu(implicit)]
48        location: Location,
49    },
50
51    #[snafu(display("Arrow error"))]
52    Arrow {
53        #[snafu(source)]
54        error: arrow_schema::ArrowError,
55    },
56
57    #[snafu(display("Internal error: {}", err_msg))]
58    Internal { err_msg: String },
59
60    #[snafu(display("Unsupported data type: {}, reason: {}", data_type, reason))]
61    UnsupportedDataType {
62        data_type: ConcreteDataType,
63        reason: String,
64    },
65
66    #[snafu(display("Internal IO error"))]
67    InternalIo {
68        #[snafu(source)]
69        error: std::io::Error,
70    },
71
72    #[snafu(display("Tokio IO error: {}", err_msg))]
73    TokioIo {
74        err_msg: String,
75        #[snafu(source)]
76        error: std::io::Error,
77    },
78
79    #[snafu(display("Failed to collect recordbatch"))]
80    CollectRecordbatch {
81        #[snafu(implicit)]
82        location: Location,
83        source: common_recordbatch::error::Error,
84    },
85
86    #[snafu(display("Failed to start HTTP server"))]
87    StartHttp {
88        #[snafu(source)]
89        error: hyper::Error,
90    },
91
92    #[snafu(display("Failed to start gRPC server"))]
93    StartGrpc {
94        #[snafu(source)]
95        error: tonic::transport::Error,
96    },
97
98    #[snafu(display("{} server is already started", server))]
99    AlreadyStarted {
100        server: String,
101        #[snafu(implicit)]
102        location: Location,
103    },
104
105    #[snafu(display("Failed to bind address {}", addr))]
106    TcpBind {
107        addr: SocketAddr,
108        #[snafu(source)]
109        error: std::io::Error,
110    },
111
112    #[snafu(display("Failed to execute query"))]
113    ExecuteQuery {
114        #[snafu(implicit)]
115        location: Location,
116        source: BoxedError,
117    },
118
119    #[snafu(display("Failed to execute plan"))]
120    ExecutePlan {
121        #[snafu(implicit)]
122        location: Location,
123        source: BoxedError,
124    },
125
126    #[snafu(display("Execute gRPC query error"))]
127    ExecuteGrpcQuery {
128        #[snafu(implicit)]
129        location: Location,
130        source: BoxedError,
131    },
132
133    #[snafu(display("Execute gRPC request error"))]
134    ExecuteGrpcRequest {
135        #[snafu(implicit)]
136        location: Location,
137        source: BoxedError,
138    },
139
140    #[snafu(display("Failed to check database validity"))]
141    CheckDatabaseValidity {
142        #[snafu(implicit)]
143        location: Location,
144        source: BoxedError,
145    },
146
147    #[snafu(display("Failed to describe statement"))]
148    DescribeStatement { source: BoxedError },
149
150    #[snafu(display("Pipeline error"))]
151    Pipeline {
152        #[snafu(source)]
153        source: pipeline::error::Error,
154        #[snafu(implicit)]
155        location: Location,
156    },
157
158    #[snafu(display("Not supported: {}", feat))]
159    NotSupported { feat: String },
160
161    #[snafu(display("Invalid request parameter: {}", reason))]
162    InvalidParameter {
163        reason: String,
164        #[snafu(implicit)]
165        location: Location,
166    },
167
168    #[snafu(display(
169        "Too many concurrent large requests, limit: {}, request size: {}",
170        ReadableSize(*limit as u64),
171        ReadableSize(*request_size as u64)
172    ))]
173    TooManyConcurrentRequests {
174        limit: usize,
175        request_size: usize,
176        #[snafu(implicit)]
177        location: Location,
178    },
179
180    #[snafu(display("Invalid query: {}", reason))]
181    InvalidQuery {
182        reason: String,
183        #[snafu(implicit)]
184        location: Location,
185    },
186
187    #[snafu(display("Failed to parse query"))]
188    FailedToParseQuery {
189        #[snafu(implicit)]
190        location: Location,
191        source: sql::error::Error,
192    },
193
194    #[snafu(display("Failed to parse InfluxDB line protocol"))]
195    InfluxdbLineProtocol {
196        #[snafu(implicit)]
197        location: Location,
198        #[snafu(source)]
199        error: influxdb_line_protocol::Error,
200    },
201
202    #[snafu(display("Failed to write row"))]
203    RowWriter {
204        #[snafu(implicit)]
205        location: Location,
206        source: common_grpc::error::Error,
207    },
208
209    #[snafu(display("Failed to convert time precision, name: {}", name))]
210    TimePrecision {
211        name: String,
212        #[snafu(implicit)]
213        location: Location,
214    },
215
216    #[snafu(display("Invalid OpenTSDB Json request"))]
217    InvalidOpentsdbJsonRequest {
218        #[snafu(source)]
219        error: serde_json::error::Error,
220        #[snafu(implicit)]
221        location: Location,
222    },
223
224    #[snafu(display("Failed to decode prometheus remote request"))]
225    DecodePromRemoteRequest {
226        #[snafu(implicit)]
227        location: Location,
228        #[snafu(source)]
229        error: prost::DecodeError,
230    },
231
232    #[snafu(display("Failed to decode OTLP request"))]
233    DecodeOtlpRequest {
234        #[snafu(implicit)]
235        location: Location,
236        #[snafu(source)]
237        error: prost::DecodeError,
238    },
239
240    #[snafu(display(
241        "OTLP metric input have incompatible existing tables, please refer to docs for details"
242    ))]
243    OtlpMetricModeIncompatible {
244        #[snafu(implicit)]
245        location: Location,
246    },
247
248    #[snafu(display("Common Meta error"))]
249    CommonMeta {
250        #[snafu(implicit)]
251        location: Location,
252        #[snafu(source)]
253        source: common_meta::error::Error,
254    },
255
256    #[snafu(display("Failed to decompress snappy prometheus remote request"))]
257    DecompressSnappyPromRemoteRequest {
258        #[snafu(implicit)]
259        location: Location,
260        #[snafu(source)]
261        error: snap::Error,
262    },
263
264    #[snafu(display("Failed to decompress zstd prometheus remote request"))]
265    DecompressZstdPromRemoteRequest {
266        #[snafu(implicit)]
267        location: Location,
268        #[snafu(source)]
269        error: std::io::Error,
270    },
271
272    #[snafu(display("Failed to compress prometheus remote request"))]
273    CompressPromRemoteRequest {
274        #[snafu(implicit)]
275        location: Location,
276        #[snafu(source)]
277        error: snap::Error,
278    },
279
280    #[snafu(display("Invalid prometheus remote request, msg: {}", msg))]
281    InvalidPromRemoteRequest {
282        msg: String,
283        #[snafu(implicit)]
284        location: Location,
285    },
286
287    #[snafu(display("Invalid prometheus remote read query result, msg: {}", msg))]
288    InvalidPromRemoteReadQueryResult {
289        msg: String,
290        #[snafu(implicit)]
291        location: Location,
292    },
293
294    #[snafu(display("Invalid Flight ticket"))]
295    InvalidFlightTicket {
296        #[snafu(source)]
297        error: api::DecodeError,
298        #[snafu(implicit)]
299        location: Location,
300    },
301
302    #[snafu(display("Tls is required for {}, plain connection is rejected", server))]
303    TlsRequired { server: String },
304
305    #[snafu(display("Failed to get user info"))]
306    Auth {
307        #[snafu(implicit)]
308        location: Location,
309        source: auth::error::Error,
310    },
311
312    #[snafu(display("Not found http or grpc authorization header"))]
313    NotFoundAuthHeader {},
314
315    #[snafu(display("Not found influx http authorization info"))]
316    NotFoundInfluxAuth {},
317
318    #[snafu(display("Unsupported http auth scheme, name: {}", name))]
319    UnsupportedAuthScheme { name: String },
320
321    #[snafu(display("Invalid visibility ASCII chars"))]
322    InvalidAuthHeaderInvisibleASCII {
323        #[snafu(source)]
324        error: hyper::header::ToStrError,
325        #[snafu(implicit)]
326        location: Location,
327    },
328
329    #[snafu(display("Invalid utf-8 value"))]
330    InvalidAuthHeaderInvalidUtf8Value {
331        #[snafu(source)]
332        error: FromUtf8Error,
333        #[snafu(implicit)]
334        location: Location,
335    },
336
337    #[snafu(display("Invalid http authorization header"))]
338    InvalidAuthHeader {
339        #[snafu(implicit)]
340        location: Location,
341    },
342
343    #[snafu(display("Invalid base64 value"))]
344    InvalidBase64Value {
345        #[snafu(source)]
346        error: DecodeError,
347        #[snafu(implicit)]
348        location: Location,
349    },
350
351    #[snafu(display("Invalid utf-8 value"))]
352    InvalidUtf8Value {
353        #[snafu(source)]
354        error: FromUtf8Error,
355        #[snafu(implicit)]
356        location: Location,
357    },
358
359    #[snafu(display("Invalid http header value"))]
360    InvalidHeaderValue {
361        #[snafu(source)]
362        error: InvalidHeaderValue,
363        #[snafu(implicit)]
364        location: Location,
365    },
366
367    #[snafu(display("Error accessing catalog"))]
368    Catalog {
369        source: catalog::error::Error,
370        #[snafu(implicit)]
371        location: Location,
372    },
373
374    #[snafu(display("Cannot find requested table: {}.{}.{}", catalog, schema, table))]
375    TableNotFound {
376        catalog: String,
377        schema: String,
378        table: String,
379        #[snafu(implicit)]
380        location: Location,
381    },
382
383    #[cfg(feature = "mem-prof")]
384    #[snafu(display("Failed to dump profile data"))]
385    DumpProfileData {
386        #[snafu(implicit)]
387        location: Location,
388        source: common_mem_prof::error::Error,
389    },
390
391    #[snafu(display("Invalid prepare statement: {}", err_msg))]
392    InvalidPrepareStatement {
393        err_msg: String,
394        #[snafu(implicit)]
395        location: Location,
396    },
397
398    #[snafu(display("Failed to build HTTP response"))]
399    BuildHttpResponse {
400        #[snafu(source)]
401        error: http::Error,
402        #[snafu(implicit)]
403        location: Location,
404    },
405
406    #[snafu(display("Failed to parse PromQL: {query:?}"))]
407    ParsePromQL {
408        query: Box<PromQuery>,
409        #[snafu(implicit)]
410        location: Location,
411        source: query::error::Error,
412    },
413
414    #[snafu(display("Failed to parse timestamp: {}", timestamp))]
415    ParseTimestamp {
416        timestamp: String,
417        #[snafu(implicit)]
418        location: Location,
419        #[snafu(source)]
420        error: query::error::Error,
421    },
422
423    #[snafu(display("{}", reason))]
424    UnexpectedResult {
425        reason: String,
426        #[snafu(implicit)]
427        location: Location,
428    },
429
430    // this error is used for custom error mapping
431    // please do not delete it
432    #[snafu(display("Other error"))]
433    Other {
434        source: BoxedError,
435        #[snafu(implicit)]
436        location: Location,
437    },
438
439    #[snafu(display("Failed to join task"))]
440    JoinTask {
441        #[snafu(source)]
442        error: tokio::task::JoinError,
443        #[snafu(implicit)]
444        location: Location,
445    },
446
447    #[cfg(feature = "pprof")]
448    #[snafu(display("Failed to dump pprof data"))]
449    DumpPprof { source: common_pprof::error::Error },
450
451    #[cfg(not(windows))]
452    #[snafu(display("Failed to update jemalloc metrics"))]
453    UpdateJemallocMetrics {
454        #[snafu(source)]
455        error: tikv_jemalloc_ctl::Error,
456        #[snafu(implicit)]
457        location: Location,
458    },
459
460    #[snafu(display("DataFrame operation error"))]
461    DataFrame {
462        #[snafu(source)]
463        error: datafusion::error::DataFusionError,
464        #[snafu(implicit)]
465        location: Location,
466    },
467
468    #[snafu(display("Failed to convert scalar value"))]
469    ConvertScalarValue {
470        source: datatypes::error::Error,
471        #[snafu(implicit)]
472        location: Location,
473    },
474
475    #[snafu(display("Expected type: {:?}, actual: {:?}", expected, actual))]
476    PreparedStmtTypeMismatch {
477        expected: ConcreteDataType,
478        actual: opensrv_mysql::ColumnType,
479        #[snafu(implicit)]
480        location: Location,
481    },
482
483    #[snafu(display(
484        "Column: {}, {} incompatible, expected: {}, actual: {}",
485        column_name,
486        datatype,
487        expected,
488        actual
489    ))]
490    IncompatibleSchema {
491        column_name: String,
492        datatype: String,
493        expected: i32,
494        actual: i32,
495        #[snafu(implicit)]
496        location: Location,
497    },
498
499    #[snafu(display("Failed to convert to json"))]
500    ToJson {
501        #[snafu(source)]
502        error: serde_json::error::Error,
503        #[snafu(implicit)]
504        location: Location,
505    },
506
507    #[snafu(display("Failed to parse payload as json"))]
508    ParseJson {
509        #[snafu(source)]
510        error: serde_json::error::Error,
511        #[snafu(implicit)]
512        location: Location,
513    },
514
515    #[snafu(display("Invalid Loki labels: {}", msg))]
516    InvalidLokiLabels {
517        msg: String,
518        #[snafu(implicit)]
519        location: Location,
520    },
521
522    #[snafu(display("Invalid Loki JSON request: {}", msg))]
523    InvalidLokiPayload {
524        msg: String,
525        #[snafu(implicit)]
526        location: Location,
527    },
528
529    #[snafu(display("Unsupported content type: {:?}", content_type))]
530    UnsupportedContentType {
531        content_type: ContentType,
532        #[snafu(implicit)]
533        location: Location,
534    },
535
536    #[snafu(display("Failed to decode url"))]
537    UrlDecode {
538        #[snafu(source)]
539        error: FromUtf8Error,
540        #[snafu(implicit)]
541        location: Location,
542    },
543
544    #[snafu(display("Failed to convert Mysql value, error: {}", err_msg))]
545    MysqlValueConversion {
546        err_msg: String,
547        #[snafu(implicit)]
548        location: Location,
549    },
550
551    #[snafu(display("Invalid table name"))]
552    InvalidTableName {
553        #[snafu(source)]
554        error: tonic::metadata::errors::ToStrError,
555        #[snafu(implicit)]
556        location: Location,
557    },
558
559    #[snafu(display("Failed to initialize a watcher for file {}", path))]
560    FileWatch {
561        path: String,
562        #[snafu(source)]
563        error: notify::Error,
564    },
565
566    #[snafu(display("Timestamp overflow: {}", error))]
567    TimestampOverflow {
568        error: String,
569        #[snafu(implicit)]
570        location: Location,
571    },
572
573    #[snafu(display("Unsupported json data type for tag: {} {}", key, ty))]
574    UnsupportedJsonDataTypeForTag {
575        key: String,
576        ty: String,
577        #[snafu(implicit)]
578        location: Location,
579    },
580
581    #[snafu(display("Convert SQL value error"))]
582    ConvertSqlValue {
583        source: datatypes::error::Error,
584        #[snafu(implicit)]
585        location: Location,
586    },
587
588    #[snafu(display("Prepare statement not found: {}", name))]
589    PrepareStatementNotFound {
590        name: String,
591        #[snafu(implicit)]
592        location: Location,
593    },
594
595    #[snafu(display("Invalid elasticsearch input, reason: {}", reason))]
596    InvalidElasticsearchInput {
597        reason: String,
598        #[snafu(implicit)]
599        location: Location,
600    },
601
602    #[snafu(display("Invalid Jaeger query, reason: {}", reason))]
603    InvalidJaegerQuery {
604        reason: String,
605        #[snafu(implicit)]
606        location: Location,
607    },
608
609    #[snafu(display("DataFusion error"))]
610    DataFusion {
611        #[snafu(source)]
612        error: DataFusionError,
613        #[snafu(implicit)]
614        location: Location,
615    },
616
617    #[snafu(display("Overflow while casting `{:?}` to Interval", val))]
618    DurationOverflow { val: Duration },
619
620    #[snafu(display("Failed to handle otel-arrow request, error message: {}", err_msg))]
621    HandleOtelArrowRequest {
622        err_msg: String,
623        #[snafu(implicit)]
624        location: Location,
625    },
626
627    #[snafu(display("Unknown hint: {}", hint))]
628    UnknownHint { hint: String },
629
630    #[snafu(display("Query has been cancelled"))]
631    Cancelled {
632        #[snafu(implicit)]
633        location: Location,
634    },
635}
636
637pub type Result<T, E = Error> = std::result::Result<T, E>;
638
639impl ErrorExt for Error {
640    fn status_code(&self) -> StatusCode {
641        use Error::*;
642        match self {
643            Internal { .. }
644            | InternalIo { .. }
645            | TokioIo { .. }
646            | StartHttp { .. }
647            | StartGrpc { .. }
648            | TcpBind { .. }
649            | BuildHttpResponse { .. }
650            | Arrow { .. }
651            | FileWatch { .. } => StatusCode::Internal,
652
653            AddressBind { .. }
654            | AlreadyStarted { .. }
655            | InvalidPromRemoteReadQueryResult { .. }
656            | OtlpMetricModeIncompatible { .. } => StatusCode::IllegalState,
657
658            UnsupportedDataType { .. } => StatusCode::Unsupported,
659
660            #[cfg(not(windows))]
661            UpdateJemallocMetrics { .. } => StatusCode::Internal,
662
663            CollectRecordbatch { .. } => StatusCode::EngineExecuteQuery,
664
665            ExecuteQuery { source, .. }
666            | ExecutePlan { source, .. }
667            | ExecuteGrpcQuery { source, .. }
668            | ExecuteGrpcRequest { source, .. }
669            | CheckDatabaseValidity { source, .. } => source.status_code(),
670
671            Pipeline { source, .. } => source.status_code(),
672            CommonMeta { source, .. } => source.status_code(),
673
674            NotSupported { .. }
675            | InvalidParameter { .. }
676            | InvalidQuery { .. }
677            | InfluxdbLineProtocol { .. }
678            | InvalidOpentsdbJsonRequest { .. }
679            | DecodePromRemoteRequest { .. }
680            | DecodeOtlpRequest { .. }
681            | CompressPromRemoteRequest { .. }
682            | DecompressSnappyPromRemoteRequest { .. }
683            | DecompressZstdPromRemoteRequest { .. }
684            | InvalidPromRemoteRequest { .. }
685            | InvalidFlightTicket { .. }
686            | InvalidPrepareStatement { .. }
687            | DataFrame { .. }
688            | PreparedStmtTypeMismatch { .. }
689            | TimePrecision { .. }
690            | UrlDecode { .. }
691            | IncompatibleSchema { .. }
692            | MysqlValueConversion { .. }
693            | ParseJson { .. }
694            | InvalidLokiLabels { .. }
695            | InvalidLokiPayload { .. }
696            | UnsupportedContentType { .. }
697            | TimestampOverflow { .. }
698            | UnsupportedJsonDataTypeForTag { .. }
699            | InvalidTableName { .. }
700            | PrepareStatementNotFound { .. }
701            | FailedToParseQuery { .. }
702            | InvalidElasticsearchInput { .. }
703            | InvalidJaegerQuery { .. }
704            | ParseTimestamp { .. }
705            | UnknownHint { .. } => StatusCode::InvalidArguments,
706
707            Catalog { source, .. } => source.status_code(),
708            RowWriter { source, .. } => source.status_code(),
709
710            TlsRequired { .. } => StatusCode::Unknown,
711            Auth { source, .. } => source.status_code(),
712            DescribeStatement { source } => source.status_code(),
713
714            NotFoundAuthHeader { .. } | NotFoundInfluxAuth { .. } => StatusCode::AuthHeaderNotFound,
715            InvalidAuthHeaderInvisibleASCII { .. }
716            | UnsupportedAuthScheme { .. }
717            | InvalidAuthHeader { .. }
718            | InvalidBase64Value { .. }
719            | InvalidAuthHeaderInvalidUtf8Value { .. } => StatusCode::InvalidAuthHeader,
720
721            TableNotFound { .. } => StatusCode::TableNotFound,
722
723            #[cfg(feature = "mem-prof")]
724            DumpProfileData { source, .. } => source.status_code(),
725
726            InvalidUtf8Value { .. } | InvalidHeaderValue { .. } => StatusCode::InvalidArguments,
727
728            TooManyConcurrentRequests { .. } => StatusCode::RuntimeResourcesExhausted,
729
730            ParsePromQL { source, .. } => source.status_code(),
731            Other { source, .. } => source.status_code(),
732
733            UnexpectedResult { .. } => StatusCode::Unexpected,
734
735            JoinTask { error, .. } => {
736                if error.is_cancelled() {
737                    StatusCode::Cancelled
738                } else if error.is_panic() {
739                    StatusCode::Unexpected
740                } else {
741                    StatusCode::Unknown
742                }
743            }
744
745            #[cfg(feature = "pprof")]
746            DumpPprof { source, .. } => source.status_code(),
747
748            ConvertScalarValue { source, .. } => source.status_code(),
749
750            ToJson { .. } | DataFusion { .. } => StatusCode::Internal,
751
752            ConvertSqlValue { source, .. } => source.status_code(),
753
754            DurationOverflow { .. } => StatusCode::InvalidArguments,
755
756            HandleOtelArrowRequest { .. } => StatusCode::Internal,
757
758            Cancelled { .. } => StatusCode::Cancelled,
759        }
760    }
761
762    fn as_any(&self) -> &dyn Any {
763        self
764    }
765}
766
767define_into_tonic_status!(Error);
768
769impl From<std::io::Error> for Error {
770    fn from(e: std::io::Error) -> Self {
771        Error::InternalIo { error: e }
772    }
773}
774
775fn log_error_if_necessary(error: &Error) {
776    if error.status_code().should_log_error() {
777        error!(error; "Failed to handle HTTP request ");
778    } else {
779        warn!(error; "Failed to handle HTTP request ");
780    }
781}
782
783impl IntoResponse for Error {
784    fn into_response(self) -> Response {
785        let error_msg = self.output_msg();
786        let status = status_code_to_http_status(&self.status_code());
787
788        log_error_if_necessary(&self);
789
790        let body = Json(json!({
791            "error": error_msg,
792        }));
793        (status, body).into_response()
794    }
795}
796
797/// Converts [StatusCode] to [HttpStatusCode].
798pub fn status_code_to_http_status(status_code: &StatusCode) -> HttpStatusCode {
799    match status_code {
800        StatusCode::Success => HttpStatusCode::OK,
801
802        // When a request is cancelled by the client (e.g., by a client side timeout),
803        // we should return a gateway timeout status code to the external client.
804        StatusCode::Cancelled | StatusCode::DeadlineExceeded => HttpStatusCode::GATEWAY_TIMEOUT,
805
806        StatusCode::Unsupported
807        | StatusCode::InvalidArguments
808        | StatusCode::InvalidSyntax
809        | StatusCode::RequestOutdated
810        | StatusCode::RegionAlreadyExists
811        | StatusCode::TableColumnExists
812        | StatusCode::TableAlreadyExists
813        | StatusCode::RegionNotFound
814        | StatusCode::DatabaseNotFound
815        | StatusCode::TableNotFound
816        | StatusCode::TableColumnNotFound
817        | StatusCode::PlanQuery
818        | StatusCode::DatabaseAlreadyExists
819        | StatusCode::TriggerAlreadyExists
820        | StatusCode::TriggerNotFound
821        | StatusCode::FlowNotFound
822        | StatusCode::FlowAlreadyExists => HttpStatusCode::BAD_REQUEST,
823
824        StatusCode::AuthHeaderNotFound
825        | StatusCode::InvalidAuthHeader
826        | StatusCode::UserNotFound
827        | StatusCode::UnsupportedPasswordType
828        | StatusCode::UserPasswordMismatch
829        | StatusCode::RegionReadonly => HttpStatusCode::UNAUTHORIZED,
830
831        StatusCode::PermissionDenied | StatusCode::AccessDenied => HttpStatusCode::FORBIDDEN,
832
833        StatusCode::RateLimited => HttpStatusCode::TOO_MANY_REQUESTS,
834
835        StatusCode::RegionNotReady
836        | StatusCode::TableUnavailable
837        | StatusCode::RegionBusy
838        | StatusCode::StorageUnavailable
839        | StatusCode::External => HttpStatusCode::SERVICE_UNAVAILABLE,
840
841        StatusCode::Internal
842        | StatusCode::Unexpected
843        | StatusCode::IllegalState
844        | StatusCode::Unknown
845        | StatusCode::RuntimeResourcesExhausted
846        | StatusCode::EngineExecuteQuery => HttpStatusCode::INTERNAL_SERVER_ERROR,
847    }
848}