/// Function that should only be used by the middleware to render a
/// telescope error into an error page.
Function that should only be used by the middleware to render a
telescope error into an error page.
Function that should only be used by the middleware to render a telescope error into an error page .
pub async fn render_error_page(&self, req: &HttpRequest) -> Result<String, ActixError> {
        // Get the status code and canonical reason for this response.
        let status_code: u16 = self.status_code().as_u16();
        let canonical_reason: &'static str = self
            .status_code()
            .canonical_reason()
            .unwrap_or("Unknown Error");
        // Create an inner template depending on the error.
        let inner_template: Template = match self {
            TelescopeError::PageNotFound => jumbotron::new(
                format!("{} - Page Not Found", status_code),
                "We could not find the page you are looking for. If you think this is in \
                error, please reach out to a coordinator or make an issue on the Github repo.",
            ),
            TelescopeError::NotImplemented => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                "The telescope developers have not finished implementing this page. Please \
                contact a coordinator AND open a GitHub issue.",
            ),
            TelescopeError::ResourceNotFound { header, message } => {
                jumbotron::new(format!("{} - {}", status_code, header), message)
            }
            TelescopeError::GatewayError { header, message } => jumbotron::new(
                format!("{} - {}", status_code, header),
                format!("{} Please contact a coordinator or faculty advisor.", message)
            ),
            TelescopeError::FutureCanceled => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                "An internal future was canceled unexpectedly. Please try again. If you \
                keep seeing this error message, contact a coordinator and open an issue on the \
                Telescope GitHub repository.",
            ),
            TelescopeError::RenderingError(err) => jumbotron::new(
                format!("{} - Internal Server Template Error", status_code),
                format!(
                    "{}. Please create an issue on Telescope's GitHub and contact a \
                coordinator.",
                    err
                ),
            ),
            TelescopeError::BadRequest { header, message, show_status_code} => {
                jumbotron::new(
                    // Decide whether or not to show the status code.
                    show_status_code
                        // With the status code
                        .then(|| format!("{} - {}", status_code, header))
                        // Without the status code
                        .unwrap_or(header.clone()),
                    message)
            }
            TelescopeError::IpExtractionError => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                "Could not determine remote IP address of this request for CSRF purposes. \
                Please contact a coordinator and create a GitHub issue.",
            ),
            TelescopeError::CsrfTokenNotFound => jumbotron::new(
                format!("{} - CSRF Token Not Found", status_code),
                "Could not find the CSRF token for this request. Please try again. If this \
                error continues, please contact a coordinator and create a GitHub issue.",
            ),
            TelescopeError::CsrfTokenMismatch => jumbotron::new(
                format!("{} - Bad CSRF Token", status_code),
                "The CSRF token supplied to the server by this request does not match the \
                one the server generated for this identity provider for this IP. If you believe \
                this is in error, please contact a coordinator and file a GitHub issue.",
            ),
            TelescopeError::RcosApiError(err) => jumbotron::new(
                format!("{} - Internal API Query Error", status_code),
                format!(
                    "Could not query the central RCOS API. Please contact a coordinator and file a \
                    GitHub issue. Internal error description: {}", err),
            ),
            TelescopeError::GitHubApiError(err) => jumbotron::new(
                format!("{} - GitHub API V4 Query Error", status_code),
                format!("Could not query the GitHub API. Please contact a coordinator and \
                    file a GitHub issue on the Telescope repository. Internal error description: {}",
                    err),
            ),
            TelescopeError::SerenityError(err) => jumbotron::new(
                format!("{} - Discord Error", status_code),
                format!("Error interacting with the Discord API. Please contact a \
                    coordinator and file a GitHub issue if this error persists. Internal error \
                    description: {}", err)
            ),
            TelescopeError::RpiCasError(err) => jumbotron::new(
                format!("{} - RPI CAS Error", status_code),
                format!("Issue communicating with the RPI CAS service. Please try again. \
                If the error persists, please contact a coordinator and create an issue on the \
                Telescope GitHub. Internal Error: {}", err)
            ),
            TelescopeError::GraphQLError { platform, errors } => {
                // Map all errors to their `Display` formatting.
                let errs: Vec<String> = errors.iter().map(|e| format!("{}", e)).collect();
                jumbotron::new(
                    format!("{} - {} Error", status_code, platform),
                    format!("The {} returned at least one error. Please \
                    contact a coordinator and create an issue on the telescope GitHub. Internal error \
                    description(s): {:?}", platform, errs)
                )
            }
            TelescopeError::InternalServerError(message) => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                format!(
                    "Telescope had an internal server error. Please contact a \
                coordinator and file a GitHub issue. Error description: {}",
                    message
                ),
            ),
            TelescopeError::InvalidForm(page) => {
                // Render page, converting errors as necessary.
                return page
                    .render()
                    .map_err(ActixError::from);
            }
            TelescopeError::NotAuthenticated => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                "You need to sign in to access this page. If you are trying to create an \
                account, please restart. Otherwise please sign in. If you have logged in, and this \
                page is unexpected, please contact a coordinator and create a GitHub issue.",
            ),
            TelescopeError::Forbidden => jumbotron::new(
                format!("{} - {}", status_code, canonical_reason),
                "You do not have the necessary permissions to access this page. If you \
                think this is in error, please contact a coordinator or faculty advisor."
            ),
        };
        // Put jumbotron in a page and return the content.
        return Page::new(req, "RCOS - Error", inner_template)
            .await
            // Convert and handle any errors.
            .map_err(ActixError::from)?
            // Render the page.
            .render()
            // Convert any error that occurs.
            .map_err(ActixError::from);
    }
pub async fn render_error_page ( & self , req : & HttpRequest ) -> Result < String , ActixError > { // Get the status code and canonical reason for this response. let status_code : u16 = self . status_code ( ) . as_u16 ( ) ; let canonical_reason : & ' static str = self . status_code ( ) . canonical_reason ( ) . unwrap_or ( " " ) ; // Create an inner template depending on the error. let inner_template : Template = match self { TelescopeError :: PageNotFound => jumbotron :: new ( format ! ( " " status_code ) , " \
 " , ) , TelescopeError :: NotImplemented => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , " \
 " , ) , TelescopeError :: ResourceNotFound { header , message } => { jumbotron :: new ( format ! ( " " status_code header ) , message ) } TelescopeError :: GatewayError { header , message } => jumbotron :: new ( format ! ( " " status_code header ) , format ! ( " " message ) ) , TelescopeError :: FutureCanceled => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , " \
 \
 " , ) , TelescopeError :: RenderingError ( err ) => jumbotron :: new ( format ! ( " " status_code ) , format ! ( " \
 " err ) , ) , TelescopeError :: BadRequest { header , message , show_status_code } => { jumbotron :: new ( // Decide whether or not to show the status code. show_status_code // With the status code . then ( | | format ! ( " " status_code header ) ) // Without the status code . unwrap_or ( header . clone ( ) ) , message ) } TelescopeError :: IpExtractionError => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , " \
 " , ) , TelescopeError :: CsrfTokenNotFound => jumbotron :: new ( format ! ( " " status_code ) , " \
 " , ) , TelescopeError :: CsrfTokenMismatch => jumbotron :: new ( format ! ( " " status_code ) , " \
 \
 " , ) , TelescopeError :: RcosApiError ( err ) => jumbotron :: new ( format ! ( " " status_code ) , format ! ( " \
 " err ) , ) , TelescopeError :: GitHubApiError ( err ) => jumbotron :: new ( format ! ( " " status_code ) , format ! ( " \
 " err ) , ) , TelescopeError :: SerenityError ( err ) => jumbotron :: new ( format ! ( " " status_code ) , format ! ( " \
 \
 " err ) ) , TelescopeError :: RpiCasError ( err ) => jumbotron :: new ( format ! ( " " status_code ) , format ! ( " \
 \
 " err ) ) , TelescopeError :: GraphQLError { platform , errors } => { // Map all errors to their `Display` formatting. let errs : Vec < String > = errors . iter ( ) . map ( | e | format ! ( " " e ) ) . collect ( ) ; jumbotron :: new ( format ! ( " " status_code platform ) , format ! ( " \
 \
 " platform errs ) ) } TelescopeError :: InternalServerError ( message ) => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , format ! ( " \
 " message ) , ) , TelescopeError :: InvalidForm ( page ) => { // Render page, converting errors as necessary. return page . render ( ) . map_err ( ActixError :: from ) ; } TelescopeError :: NotAuthenticated => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , " \
 \
 " , ) , TelescopeError :: Forbidden => jumbotron :: new ( format ! ( " " status_code canonical_reason ) , " \
 " ) , } ; // Put jumbotron in a page and return the content. return Page :: new ( req , " " , inner_template ) . await // Convert and handle any errors. . map_err ( ActixError :: from ) ? // Render the page. . render ( ) // Convert any error that occurs. . map_err ( ActixError :: from ) ; }
Function that should only be used by the middleware to render a
telescope error into an error page.
Function that should only be used by the middleware to render a telescope error into an error page .
&self
req
&HttpRequest