In these lines:
fn post_error(err: JsonPayloadError, req: &HttpRequest) -> Error {
let extns = req.extensions();
let state = extns.get::<web::Data<AppState>>().unwrap();
The unwrap() causes a panic. The state did not get returned from the extension.
This is with the unmodified sample code from v4