Implemented error reporting solution

This commit is contained in:
Anton Stubenbord
2022-11-14 00:08:07 +01:00
parent b5aac36b2b
commit 511f8ca3f4
33 changed files with 475 additions and 110 deletions

View File

@@ -0,0 +1,61 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:paperless_mobile/core/model/github_error_report.model.dart';
import 'package:paperless_mobile/core/widgets/error_report_page.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:paperless_mobile/extensions/dart_extensions.dart';
class GithubIssueService {
static void openCreateGithubIssue({
String? title,
String? body,
List<String>? labels,
String? milestone,
List<String>? assignees,
String? project,
}) {
final Uri uri = Uri(
scheme: "https",
host: "github.com",
path: "astubenbord/paperless-mobile/issues/new",
queryParameters: {}
..tryPutIfAbsent('title', () => title)
//..tryPutIfAbsent('body', () => body) //TODO: Figure out how to pass long body via url
..tryPutIfAbsent('labels', () => labels?.join(','))
..tryPutIfAbsent('milestone', () => milestone)
..tryPutIfAbsent('assignees', () => assignees?.join(','))
..tryPutIfAbsent('project', () => project),
);
log("[GitHubIssueService] Creating GitHub issue: " + uri.toString());
launchUrl(
uri,
mode: LaunchMode.externalApplication,
);
}
static void createIssueFromError(
BuildContext context, {
StackTrace? stackTrace,
}) async {
final errorDescription = await Navigator.push<GithubErrorReport>(
context,
MaterialPageRoute(
builder: (context) => ErrorReportPage(
stackTrace: stackTrace,
),
),
);
if (errorDescription == null) {
return;
}
return openCreateGithubIssue(
title: errorDescription.shortDescription,
body: errorDescription.longDescription ?? '',
labels: ['error report'],
);
}
}

View File

@@ -0,0 +1,35 @@
import 'dart:convert';
import 'package:http/http.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/core/model/paperless_server_information.dart';
import 'package:paperless_mobile/core/store/local_vault.dart';
@injectable
class PaperlessServerInformationService {
final BaseClient client;
final LocalVault localStore;
PaperlessServerInformationService(
@Named("timeoutClient") this.client,
this.localStore,
);
Future<PaperlessServerInformation> getInformation() async {
final response = await client.get(Uri.parse("/api/ui_settings/"));
final version =
response.headers[PaperlessServerInformation.versionHeader] ?? 'unknown';
final apiVersion = int.tryParse(
response.headers[PaperlessServerInformation.apiVersionHeader] ?? '1');
final String username =
jsonDecode(utf8.decode(response.bodyBytes))['username'];
final String? host =
response.headers[PaperlessServerInformation.hostHeader];
return PaperlessServerInformation(
username: username,
version: version,
apiVersion: apiVersion,
host: host,
);
}
}

View File

@@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:paperless_mobile/core/bloc/document_status_cubit.dart';
import 'package:paperless_mobile/core/model/document_processing_status.dart';
import 'package:paperless_mobile/di_initializer.dart';
@@ -9,7 +10,6 @@ import 'package:paperless_mobile/features/documents/model/document.model.dart';
import 'package:paperless_mobile/features/documents/model/paged_search_result.dart';
import 'package:paperless_mobile/features/login/model/authentication_information.dart';
import 'package:paperless_mobile/util.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:injectable/injectable.dart';
import 'package:web_socket_channel/io.dart';