A Flight server that uses all the Flight-specific errors.
| 406 | |
| 407 | |
| 408 | class ErrorFlightServer(FlightServerBase): |
| 409 | """A Flight server that uses all the Flight-specific errors.""" |
| 410 | |
| 411 | @staticmethod |
| 412 | def error_cases(): |
| 413 | return { |
| 414 | "internal": flight.FlightInternalError, |
| 415 | "timedout": flight.FlightTimedOutError, |
| 416 | "cancel": flight.FlightCancelledError, |
| 417 | "unauthenticated": flight.FlightUnauthenticatedError, |
| 418 | "unauthorized": flight.FlightUnauthorizedError, |
| 419 | "notimplemented": NotImplementedError, |
| 420 | "invalid": pa.ArrowInvalid, |
| 421 | "key": KeyError, |
| 422 | } |
| 423 | |
| 424 | def do_action(self, context, action): |
| 425 | error_cases = ErrorFlightServer.error_cases() |
| 426 | if action.type in error_cases: |
| 427 | raise error_cases[action.type]("foo") |
| 428 | elif action.type == "protobuf": |
| 429 | err_msg = b'this is an error message' |
| 430 | raise flight.FlightUnauthorizedError("foo", err_msg) |
| 431 | raise NotImplementedError |
| 432 | |
| 433 | def list_flights(self, context, criteria): |
| 434 | yield flight.FlightInfo( |
| 435 | pa.schema([]), |
| 436 | flight.FlightDescriptor.for_path('/foo'), |
| 437 | [] |
| 438 | ) |
| 439 | raise flight.FlightInternalError("foo") |
| 440 | |
| 441 | def do_put(self, context, descriptor, reader, writer): |
| 442 | if descriptor.command == b"internal": |
| 443 | raise flight.FlightInternalError("foo") |
| 444 | elif descriptor.command == b"timedout": |
| 445 | raise flight.FlightTimedOutError("foo") |
| 446 | elif descriptor.command == b"cancel": |
| 447 | raise flight.FlightCancelledError("foo") |
| 448 | elif descriptor.command == b"unauthenticated": |
| 449 | raise flight.FlightUnauthenticatedError("foo") |
| 450 | elif descriptor.command == b"unauthorized": |
| 451 | raise flight.FlightUnauthorizedError("foo") |
| 452 | elif descriptor.command == b"protobuf": |
| 453 | err_msg = b'this is an error message' |
| 454 | raise flight.FlightUnauthorizedError("foo", err_msg) |
| 455 | |
| 456 | |
| 457 | class ExchangeFlightServer(FlightServerBase): |
no outgoing calls