<commit_before>use std::fmt;

use super::{AppError, InternalAppErrorStatic};
use crate::util::{json_response, AppResponse};

use chrono::NaiveDateTime;
use conduit::{header, StatusCode};

/// Generates a response with the provided status and description as JSON
fn json_error(detail: &str, status: StatusCode) -> AppResponse {
    #[derive(Serialize)]
    struct StringError<'a> {
        detail: &'a str,
    }
    #[derive(Serialize)]
    struct Bad<'a> {
        errors: [StringError<'a>; 1],
    }

    let mut response = json_response(&Bad {
        errors: [StringError { detail }],
    });
    *response.status_mut() = status;
    response
}

// The following structs are emtpy and do not provide a custom message to the user

#[derive(Debug)]
pub(crate) struct NotFound;

// This struct has this helper impl for use as `NotFound.into()`
impl From<NotFound> for AppResponse {
    fn from(_: NotFound) -> AppResponse {<commit_msg>errors::json: Use `json!` macro to simplify JSON serialization code<commit_after>use std::fmt;

use super::{AppError, InternalAppErrorStatic};
use crate::util::{json_response, AppResponse};

use chrono::NaiveDateTime;
use conduit::{header, StatusCode};

/// Generates a response with the provided status and description as JSON
fn json_error(detail: &str, status: StatusCode) -> AppResponse {
    let json = json!({ "errors": [{ "detail": detail }] });

    let mut response = json_response(&json);
    *response.status_mut() = status;
    response
}

// The following structs are emtpy and do not provide a custom message to the user

#[derive(Debug)]
pub(crate) struct NotFound;

// This struct has this helper impl for use as `NotFound.into()`
impl From<NotFound> for AppResponse {
    fn from(_: NotFound) -> AppResponse {
{'fraction_non_alphanumeric': 0.1254256526674234, 'fraction_numerical': 0.0005675368898978433, 'mean_word_length': 4.278443113772455, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480077', 'n_tokens_mistral': 513, 'n_tokens_neox': 525, 'n_words': 177}