Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoRB committed Dec 9, 2023
1 parent 5d007c3 commit 7b90b5b
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import '../dtos/city_dto.dart';
import '../error_handlers/not_found_exception.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ApplicationGenerator extends GeneratorForAnnotation<Application> {
static final _classTypeName = 'classType';
static final _fieldNameName = 'name';


@override
String? generateForAnnotatedElement(
Element element,
Expand Down Expand Up @@ -134,8 +133,10 @@ class ApplicationGenerator extends GeneratorForAnnotation<Application> {
);
final inject = param.metadata
.firstWhereOrNull((element) => element.runtimeType == Inject);
final injectName =
inject?.computeConstantValue()?.getField(_fieldNameName)?.toStringValue();
final injectName = inject
?.computeConstantValue()
?.getField(_fieldNameName)
?.toStringValue();
if (injectName != null && injectName.isNotEmpty) {
return "injectRegister.resolve<$className>(name: '$injectName,')";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'http_server_error_exception.dart';

/// A custom exception representing a "Bad Gateway" error (HTTP 502).
///
/// This exception extends [HttpServerErrorException] and is thrown to indicate
/// that the server, while acting as a gateway or proxy, received an invalid
/// response from an inbound server. It includes a human-readable [message] and
/// has an HTTP status code of [HttpStatus.badGateway].
class BadGatewayException extends HttpServerErrorException {
/// Creates a [BadGatewayException] with the specified [message].
///
/// The [message] is a human-readable description of the bad gateway error.
const BadGatewayException(String message)
: super(message, HttpStatus.badGateway);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Bad Request" error (HTTP 400).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the server cannot or will not process the request due to something
/// that is perceived to be a client error. It includes a human-readable [message]
/// and has an HTTP status code of [HttpStatus.badRequest].
class BadRequestException extends HttpClientErrorException {
/// Creates a [BadRequestException] with the specified [message].
///
/// The [message] is a human-readable description of the bad request error.
const BadRequestException(String message)
: super(message, HttpStatus.badRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Conflict" error (HTTP 409).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the request could not be completed due to a conflict with the current
/// state of the target resource. It includes a human-readable [message] and
/// has an HTTP status code of [HttpStatus.conflict].
class ConflictException extends HttpClientErrorException {
/// Creates a [ConflictException] with the specified [message].
///
/// The [message] is a human-readable description of the conflict error.
const ConflictException(String message) : super(message, HttpStatus.conflict);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Forbidden" error (HTTP 403).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the server understood the request, but it refuses to authorize it.
/// It includes a human-readable [message] and has an HTTP status code of
/// [HttpStatus.forbidden].
class ForbiddenException extends HttpClientErrorException {
/// Creates a [ForbiddenException] with the specified [message].
///
/// The [message] is a human-readable description of the forbidden error.
const ForbiddenException(String message)
: super(message, HttpStatus.forbidden);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'http_server_error_exception.dart';

/// A custom exception representing a "Gateway Timeout" error (HTTP 504).
///
/// This exception extends [HttpServerErrorException] and is thrown to indicate
/// that the server, while acting as a gateway or proxy, did not receive a timely
/// response from an upstream server or some other auxiliary server. It includes
/// a human-readable [message] and has an HTTP status code of [HttpStatus.gatewayTimeout].
class GatewayTimeoutException extends HttpServerErrorException {
/// Creates a [GatewayTimeoutException] with the specified [message].
///
/// The [message] is a human-readable description of the gateway timeout error.
const GatewayTimeoutException(String message)
: super(message, HttpStatus.gatewayTimeout);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Gone" error (HTTP 410).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the requested resource is no longer available at the server and no
/// forwarding address is known. It includes a human-readable [message] and has
/// an HTTP status code of [HttpStatus.gone].
class GoneException extends HttpClientErrorException {
/// Creates a [GoneException] with the specified [message].
///
/// The [message] is a human-readable description of the gone error.
const GoneException(String message) : super(message, HttpStatus.gone);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import 'package:dartness_server/exception.dart';

/// Custom exception class representing HTTP client errors.
///
/// This class extends [HttpStatusCodeException] and is used to indicate errors
/// that occur on the client side of an HTTP request. It includes a human-readable
/// [message] describing the error and an associated HTTP [statusCode].
class HttpClientErrorException extends HttpStatusCodeException {
/// Creates an instance of [HttpClientErrorException] with the specified [message]
/// and HTTP [statusCode].
const HttpClientErrorException(super.message, super.statusCode);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import 'package:dartness_server/exception.dart';

/// A custom exception representing a generic HTTP server error.
///
/// This exception extends [HttpStatusCodeException] and is used to signal
/// errors that occur on the server side. It includes a human-readable [message]
/// and an associated HTTP [statusCode] indicating the nature of the server error.
class HttpServerErrorException extends HttpStatusCodeException {
/// Creates an [HttpServerErrorException] with the specified [message] and [statusCode].
///
/// The [message] is a human-readable description of the server error, and
/// [statusCode] represents the HTTP status code associated with the error.
const HttpServerErrorException(super.message, super.statusCode);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/// Exception for HTTP status code.
/// This abstract class is used to create custom exceptions for HTTP status codes.
/// An abstract base class for custom exceptions representing HTTP status code errors.
///
///
/// Example:
/// ```dart
/// class NotFoundException extends HttpStatusCodeException {
/// const NotFoundException(String message) : super(message, HttpStatus.notFound);
/// }
/// ```
/// This class extends [Exception] and serves as a foundation for creating specific
/// exceptions related to HTTP status codes. It includes a human-readable [message]
/// describing the error and an associated HTTP [statusCode].
abstract class HttpStatusCodeException implements Exception {
/// Creates an instance of [HttpStatusCodeException] with the specified [message]
/// and HTTP [statusCode].
const HttpStatusCodeException(this.message, this.statusCode);

/// The message of the exception.
/// A human-readable description of the exception.
final String message;

/// The http status code of the exception.
/// The HTTP status code associated with the exception.
final int statusCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import 'dart:io';

import 'http_server_error_exception.dart';

/// A custom exception representing an internal server error (HTTP 500).
///
/// This exception extends [HttpServerErrorException] and is specifically used
/// to indicate that an unexpected error occurred on the server side. It includes
/// a human-readable [message] and has an HTTP status code of [HttpStatus.internalServerError].
class InternalServerErrorException extends HttpServerErrorException {
/// Creates an [InternalServerErrorException] with the specified [message].
///
/// The [message] is a human-readable description of the internal server error.
const InternalServerErrorException(String message)
: super(message, HttpStatus.internalServerError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Method Not Allowed" error (HTTP 405).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the HTTP method used on a resource is not supported. It includes a
/// human-readable [message] and has an HTTP status code of [HttpStatus.methodNotAllowed].
class MethodNotAllowedException extends HttpClientErrorException {
/// Creates a [MethodNotAllowedException] with the specified [message].
///
/// The [message] is a human-readable description of the method not allowed error.
const MethodNotAllowedException(String message)
: super(message, HttpStatus.methodNotAllowed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Not Acceptable" error (HTTP 406).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the server cannot produce a response matching the list of acceptable
/// values defined in the request's headers. It includes a human-readable [message]
/// and has an HTTP status code of [HttpStatus.notAcceptable].
class NotAcceptableException extends HttpClientErrorException {
/// Creates a [NotAcceptableException] with the specified [message].
///
/// The [message] is a human-readable description of the not acceptable error.
const NotAcceptableException(String message)
: super(message, HttpStatus.notAcceptable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'http_server_error_exception.dart';

/// A custom exception representing a "Not Implemented" error (HTTP 501).
///
/// This exception extends [HttpServerErrorException] and is thrown to indicate
/// that the server does not support the functionality required to fulfill
/// the request. It includes a human-readable [message] and has an HTTP status
/// code of [HttpStatus.notImplemented].
class NotImplementedException extends HttpServerErrorException {
/// Creates a [NotImplementedException] with the specified [message].
///
/// The [message] is a human-readable description of the not implemented error.
const NotImplementedException(String message)
: super(message, HttpStatus.notImplemented);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import 'dart:io';

import 'http_server_error_exception.dart';

/// A custom exception representing a "Service Unavailable" error (HTTP 503).
///
/// This exception extends [HttpServerErrorException] and is thrown to indicate
/// that the server is currently unable to handle the request. It includes a
/// human-readable [message] and has an HTTP status code of [HttpStatus.serviceUnavailable].
class ServiceUnavailableException extends HttpServerErrorException {
/// Creates a [ServiceUnavailableException] with the specified [message].
///
/// The [message] is a human-readable description of the service unavailable error.
const ServiceUnavailableException(String message)
: super(message, HttpStatus.serviceUnavailable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing a "Too Many Requests" error (HTTP 429).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the client has sent too many requests in a given amount of time. It
/// includes a human-readable [message] and has an HTTP status code of
/// [HttpStatus.tooManyRequests].
class TooManyRequestsException extends HttpClientErrorException {
/// Creates a [TooManyRequestsException] with the specified [message].
///
/// The [message] is a human-readable description of the too many requests error.
const TooManyRequestsException(String message)
: super(message, HttpStatus.tooManyRequests);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing an "Unauthorized" error (HTTP 401).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the request has not been applied because it lacks valid authentication
/// credentials for the target resource. It includes a human-readable [message]
/// and has an HTTP status code of [HttpStatus.unauthorized].
class UnauthorizedException extends HttpClientErrorException {
/// Creates an [UnauthorizedException] with the specified [message].
///
/// The [message] is a human-readable description of the unauthorized error.
const UnauthorizedException(String message)
: super(message, HttpStatus.unauthorized);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing an "Unprocessable Entity" error (HTTP 422).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the server understands the content type of the request entity but was
/// unable to process the contained instructions. It includes a human-readable
/// [message] and has an HTTP status code of [HttpStatus.unprocessableEntity].
class UnprocessableEntityException extends HttpClientErrorException {
/// Creates an [UnprocessableEntityException] with the specified [message].
///
/// The [message] is a human-readable description of the unprocessable entity error.
const UnprocessableEntityException(String message)
: super(message, HttpStatus.unprocessableEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'dart:io';

import 'package:dartness_server/src/exception/http_client_error_exception.dart';

/// A custom exception representing an "Unprocessable Entity" error (HTTP 422).
///
/// This exception extends [HttpClientErrorException] and is thrown to indicate
/// that the server understands the content type of the request entity but was
/// unable to process the contained instructions. It includes a human-readable
/// [message] and has an HTTP status code of [HttpStatus.unprocessableEntity].
class UnprocessableEntityException extends HttpClientErrorException {
/// Creates an [UnprocessableEntityException] with the specified [message].
///
/// The [message] is a human-readable description of the unprocessable entity error.
const UnprocessableEntityException(String message)
: super(message, HttpStatus.unsupportedMediaType);
: super(message, HttpStatus.unprocessableEntity);
}

0 comments on commit 7b90b5b

Please sign in to comment.