Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/http_exception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "build"

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest] # or: macos-latest, windows-latest
channel: ['2.15.0', stable, beta, dev, main] # or: 'beta', 'dev' or 'main'

steps:
- uses: actions/checkout@v4

- uses: dart-lang/setup-dart@v1.6.1
with:
sdk: ${{ matrix.channel }}

- id: disabled_analytics_dart
name: Disabled Analytics Dart
run: dart --disable-analytics

- name: Install dependencies
run: dart pub get

# Verifies if the dart code is formatted well
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .
# --set-exit-if-changed stops execution if the any code is not well formatted
# --output=none prints files which needs to be formatted

# Checks for Symantic errors. Can be configured using analysis_options.yaml
- name: Analyze project source
run: dart analyze --fatal-infos
# optionally use --fatal-warnings to stop execution if any warnings are found

- name: Run Tests
run: |
dart pub global activate coverage
dart pub global run coverage:test_with_coverage

# - name: Check Code Coverage
# uses: VeryGoodOpenSource/very_good_coverage@v2
# with:
# path: "./coverage/lcov.info"
# min_coverage: 100

- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# See https://www.dartlang.org/guides/libraries/private-files
# Files and directories created by pub
build/
.idea/
packages
.packages
.dart_tool/
.pub/

# Remove the following pattern if you wish to check in your lock file
pubspec.lock

# Directory created by dartdoc
doc/api/

# JetBrains IDEs
.idea/
/.codecov-token

# Coverage reports
coverage/
lcov.info

# dotenv environment variables file
.env*

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map

.flutter-plugins
.flutter-plugins-dependencies
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ linter:
- empty_statements
- hash_and_equals
- invariant_booleans
- iterable_contains_unrelated_type
- list_remove_unrelated_type
# - iterable_contains_unrelated_type
# - list_remove_unrelated_type
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_duplicate_case_values
Expand All @@ -34,7 +34,7 @@ linter:
- always_declare_return_types
# - always_put_control_body_on_new_line # works against dartfmt
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
# - always_require_non_null_named_parameters
# - always_specify_types
- annotate_overrides
- avoid_annotating_with_dynamic
Expand All @@ -53,7 +53,7 @@ linter:
# - avoid_private_typedef_functions # not considered a useful rule
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null
# - avoid_returning_null
- avoid_returning_this
- avoid_setters_without_getters
- avoid_single_cascade_in_expression_statements
Expand Down
31 changes: 16 additions & 15 deletions lib/http_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'http_status.dart';
class HttpException implements Exception {
final int status;
final String message;
final Map<String, dynamic> data;
final Map<String, dynamic>? data;

const HttpException(
[this.status = HttpStatus.INTERNAL_SERVER_ERROR,
Expand All @@ -26,101 +26,102 @@ class HttpException implements Exception {

/// 400 Bad Request
class BadRequestException extends HttpException {
const BadRequestException([Map<String, dynamic> data, String detail = ''])
const BadRequestException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.BAD_REQUEST,
'Bad Request${detail != '' ? ': ' : ''}$detail', data);
}

/// 401 Unauthorized
class UnauthorizedException extends HttpException {
const UnauthorizedException([Map<String, dynamic> data, String detail = ''])
const UnauthorizedException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.UNAUTHORIZED,
'Unauthorized${detail != '' ? ': ' : ''}$detail', data);
}

/// 402 Payment Required
class PaymentRequiredException extends HttpException {
const PaymentRequiredException(
[Map<String, dynamic> data, String detail = ''])
[Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.PAYMENT_REQUIRED,
'Payment Required${detail != '' ? ': ' : ''}$detail', data);
}

/// 403 Forbidden
class ForbiddenException extends HttpException {
const ForbiddenException([Map<String, dynamic> data, String detail = ''])
const ForbiddenException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.FORBIDDEN,
'Forbidden${detail != '' ? ': ' : ''}$detail', data);
}

/// 404 Not Found
class NotFoundException extends HttpException {
const NotFoundException([Map<String, dynamic> data, String detail = ''])
const NotFoundException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.NOT_FOUND,
'Not Found${detail != '' ? ': ' : ''}$detail', data);
}

/// 405 Method Not Allowed
class MethodNotAllowed extends HttpException {
const MethodNotAllowed([Map<String, dynamic> data, String detail = ''])
const MethodNotAllowed([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.METHOD_NOT_ALLOWED,
'Method Not Allowed${detail != '' ? ': ' : ''}$detail', data);
}

/// 406 Not Acceptable
class NotAcceptableException extends HttpException {
const NotAcceptableException([Map<String, dynamic> data, String detail = ''])
const NotAcceptableException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.NOT_ACCEPTABLE,
'Not Acceptable${detail != '' ? ': ' : ''}$detail', data);
}

/// 409 Conflict
class ConflictException extends HttpException {
const ConflictException([Map<String, dynamic> data, String detail = ''])
const ConflictException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.CONFLICT, 'Conflict${detail != '' ? ': ' : ''}$detail',
data);
}

/// 410 Gone
class GoneException extends HttpException {
const GoneException([Map<String, dynamic> data, String detail = ''])
const GoneException([Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.GONE, 'Gone${detail != '' ? ': ' : ''}$detail', data);
}

/// 412 Precondition Failed
class PreconditionFailedException extends HttpException {
const PreconditionFailedException(
[Map<String, dynamic> data, String detail = ''])
[Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.PRECONDITION_FAILED,
'Precondition Failed${detail != '' ? ': ' : ''}$detail', data);
}

/// 415 Unsupported Media Type
class UnsupportedMediaTypeException extends HttpException {
const UnsupportedMediaTypeException(
[Map<String, dynamic> data, String detail = ''])
[Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.UNSUPPORTED_MEDIA_TYPE,
'Unsupported Media Type${detail != '' ? ': ' : ''}$detail', data);
}

/// 429 Too Many Requests
class TooManyRequestsException extends HttpException {
const TooManyRequestsException(
[Map<String, dynamic> data, String detail = ''])
[Map<String, dynamic>? data, String detail = ''])
: super(429, 'Too Many Requests${detail != '' ? ': ' : ''}$detail', data);
}

/// 501 Not Implemented
class NotImplementedException extends HttpException {
const NotImplementedException([Map<String, dynamic> data, String detail = ''])
const NotImplementedException(
[Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.NOT_IMPLEMENTED,
'Not Implemented${detail != '' ? ': ' : ''}$detail', data);
}

/// 503 Service Unavailable
class ServiceUnavailableException extends HttpException {
const ServiceUnavailableException(
[Map<String, dynamic> data, String detail = ''])
[Map<String, dynamic>? data, String detail = ''])
: super(HttpStatus.SERVICE_UNAVAILABLE,
'Service Unavailable${detail != '' ? ': ' : ''}$detail', data);
}
Loading