use of ninja.diagnostics.DiagnosticError in project ninja by ninjaframework.
the class NinjaDefault method getNotFoundResult.
@Override
public Result getNotFoundResult(Context context) {
if (isDiagnosticsEnabled()) {
DiagnosticError diagnosticError = DiagnosticErrorBuilder.build404NotFoundDiagnosticError(true);
return Results.notFound().render(diagnosticError);
}
String messageI18n = messages.getWithDefault(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_DEFAULT, context, Optional.<Result>empty());
Message message = new Message(messageI18n);
Result result = Results.notFound().supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML).fallbackContentType(Result.TEXT_HTML).render(message).template(ninjaProperties.getWithDefault(NinjaConstant.LOCATION_VIEW_HTML_NOT_FOUND_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND));
return result;
}
use of ninja.diagnostics.DiagnosticError in project ninja by ninjaframework.
the class NinjaDefault method getForbiddenResult.
@Override
public Result getForbiddenResult(Context context) {
// diagnostic mode
if (isDiagnosticsEnabled()) {
DiagnosticError diagnosticError = DiagnosticErrorBuilder.build403ForbiddenDiagnosticError();
return Results.forbidden().render(diagnosticError);
}
String messageI18n = messages.getWithDefault(NinjaConstant.I18N_NINJA_SYSTEM_FORBIDDEN_REQUEST_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_FORBIDDEN_REQUEST_TEXT_DEFAULT, context, Optional.<Result>empty());
Message message = new Message(messageI18n);
Result result = Results.forbidden().supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML).fallbackContentType(Result.TEXT_HTML).render(message).template(ninjaProperties.getWithDefault(NinjaConstant.LOCATION_VIEW_HTML_FORBIDDEN_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_FORBIDDEN));
return result;
}
use of ninja.diagnostics.DiagnosticError in project ninja by ninjaframework.
the class NinjaDefault method getInternalServerErrorResult.
@Override
public Result getInternalServerErrorResult(Context context, Exception exception, Result underlyingResult) {
if (isDiagnosticsEnabled()) {
DiagnosticError diagnosticError = DiagnosticErrorBuilder.build500InternalServerErrorDiagnosticError(exception, true, underlyingResult);
return Results.internalServerError().render(diagnosticError);
}
logger.error("Emitting bad request 500. Something really wrong when calling route: {} (class: {} method: {})", context.getRequestPath(), context.getRoute().getControllerClass(), context.getRoute().getControllerMethod(), exception);
Message message = buildErrorMessage(context, NinjaConstant.I18N_NINJA_SYSTEM_INTERNAL_SERVER_ERROR_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_INTERNAL_SERVER_ERROR_TEXT_DEFAULT, Optional.ofNullable(exception), Optional.<Result>empty());
return Results.internalServerError().supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML).fallbackContentType(Result.TEXT_HTML).render(message).template(ninjaProperties.getWithDefault(NinjaConstant.LOCATION_VIEW_HTML_INTERNAL_SERVER_ERROR_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_INTERNAL_SERVER_ERROR));
}
use of ninja.diagnostics.DiagnosticError in project ninja by ninjaframework.
the class NinjaDefault method getUnauthorizedResult.
@Override
public Result getUnauthorizedResult(Context context) {
if (isDiagnosticsEnabled()) {
DiagnosticError diagnosticError = DiagnosticErrorBuilder.build401UnauthorizedDiagnosticError();
return Results.unauthorized().render(diagnosticError);
}
String messageI18n = messages.getWithDefault(NinjaConstant.I18N_NINJA_SYSTEM_UNAUTHORIZED_REQUEST_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_UNAUTHORIZED_REQUEST_TEXT_DEFAULT, context, Optional.<Result>empty());
Message message = new Message(messageI18n);
// WWW-Authenticate must be included per the spec
// http://www.ietf.org/rfc/rfc2617.txt 3.2.1 The WWW-Authenticate Response Header
Result result = Results.unauthorized().addHeader(Result.WWW_AUTHENTICATE, "None").supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML).fallbackContentType(Result.TEXT_HTML).render(message).template(ninjaProperties.getWithDefault(NinjaConstant.LOCATION_VIEW_HTML_UNAUTHORIZED_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_UNAUTHORIZED));
return result;
}
use of ninja.diagnostics.DiagnosticError in project ninja by ninjaframework.
the class NinjaDefault method getBadRequestResult.
@Override
public Result getBadRequestResult(Context context, Exception exception) {
if (isDiagnosticsEnabled()) {
DiagnosticError diagnosticError = DiagnosticErrorBuilder.build400BadRequestDiagnosticError(exception, true);
return Results.badRequest().render(diagnosticError);
}
String messageI18n = messages.getWithDefault(NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_DEFAULT, context, Optional.<Result>empty());
Message message = new Message(messageI18n);
Result result = Results.badRequest().supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML).fallbackContentType(Result.TEXT_HTML).render(message).template(ninjaProperties.getWithDefault(NinjaConstant.LOCATION_VIEW_HTML_BAD_REQUEST_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST));
return result;
}
Aggregations