def retrieve(self, request: RetrieveDataRequest) -> responses.Response: """ Call the retrieve method on the database. This method will handle any error that happens when retrieving data. Params: request: Request to handle. Return: Output of the data insertion. """ if not request: return responses.ResponseFailure.invalid_request_error(request) try: result = self.database.retrieve(request.key) return responses.ResponseSuccess(result) except Exception as exc: logger.exception("Retrieve data use case failure", exc_info=True) return responses.ResponseFailure.database_error(exc)
def validate(self, request: PackageRequest) -> responses.Response: """ Call the validate method on the validator. This method will handle any error that happens during validation. Params: request: Request to handle. Return: Output of the validation. """ if not request: return responses.ResponseFailure.invalid_request_error(request) try: result = self.validator.validate(request.package) return responses.ResponseSuccess(result) except Exception as exc: logger.exception("Package check use case failure", exc_info=True) return responses.ResponseFailure.validator_error(exc)
def build(self, request: BuildRequest) -> responses.Response: """ Call the build method on the builder. This method will handle any error that happens when starting build. Params: request: Request to handle. Return: Output of the build. """ if not request: return responses.ResponseFailure.invalid_request_error(request) try: result = self.builder.build(request.package, request.opts) return responses.ResponseSuccess(result) except Exception as exc: logger.exception("Package scratch build use case failure", exc_info=True) return responses.ResponseFailure.builder_error(exc)
def notify(self, request: NotifyRequest) -> responses.Response: """ Call the notify method on the notifier. This method will handle any error that happens when sending notification. Params: request: Request to handle. Return: Output of the notification. """ if not request: return responses.ResponseFailure.invalid_request_error(request) try: result = self.notifier.notify(request.package, request.message, request.opts) return responses.ResponseSuccess(result) except Exception as exc: logger.exception("Notify user use case failure", exc_info=True) return responses.ResponseFailure.notifier_error(exc)
def submit_patch(self, request: SubmitPatchRequest) -> responses.Response: """ Call the submit_patch method on the patcher. This method will handle any error that happens during submit of the patch. Params: request: Request to handle. Return: Output of the build. """ if not request: return responses.ResponseFailure.invalid_request_error(request) try: result = self.patcher.submit_patch( request.package, request.patch, request.opts ) return responses.ResponseSuccess(result) except Exception as exc: logger.exception("Submit patch use case failure", exc_info=True) return responses.ResponseFailure.patcher_error(exc)