|
|
@ -29,22 +29,17 @@ namespace Prowlarr.Http.ErrorManagement
|
|
|
|
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
|
|
|
|
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
|
|
|
|
var exception = exceptionHandlerPathFeature?.Error;
|
|
|
|
var exception = exceptionHandlerPathFeature?.Error;
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Warn(exception);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var statusCode = HttpStatusCode.InternalServerError;
|
|
|
|
var statusCode = HttpStatusCode.InternalServerError;
|
|
|
|
var errorModel = new ErrorModel
|
|
|
|
var errorModel = new ErrorModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Message = exception.Message,
|
|
|
|
Message = exception?.Message,
|
|
|
|
Description = exception.ToString()
|
|
|
|
Description = exception?.ToString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (exception is ApiException apiException)
|
|
|
|
if (exception is ApiException apiException)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Warn(apiException, "API Error:\n{0}", apiException.Message);
|
|
|
|
_logger.Warn(apiException, "API Error:\n{0}", apiException.Message);
|
|
|
|
|
|
|
|
|
|
|
|
/* var body = RequestStream.FromStream(context.Request.Body).AsString();
|
|
|
|
|
|
|
|
_logger.Trace("Request body:\n{0}", body);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errorModel = new ErrorModel(apiException);
|
|
|
|
errorModel = new ErrorModel(apiException);
|
|
|
|
statusCode = apiException.StatusCode;
|
|
|
|
statusCode = apiException.StatusCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,30 +54,15 @@ namespace Prowlarr.Http.ErrorManagement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (exception is NzbDroneClientException clientException)
|
|
|
|
else if (exception is NzbDroneClientException clientException)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
errorModel = new ErrorModel
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Message = exception.Message,
|
|
|
|
|
|
|
|
Description = exception.ToString()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
statusCode = clientException.StatusCode;
|
|
|
|
statusCode = clientException.StatusCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (exception is ModelNotFoundException notFoundException)
|
|
|
|
else if (exception is ModelNotFoundException)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
errorModel = new ErrorModel
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Message = exception.Message,
|
|
|
|
|
|
|
|
Description = exception.ToString()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
statusCode = HttpStatusCode.NotFound;
|
|
|
|
statusCode = HttpStatusCode.NotFound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (exception is ModelConflictException conflictException)
|
|
|
|
else if (exception is ModelConflictException)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Error(exception, "DB error");
|
|
|
|
_logger.Error(exception, "DB error");
|
|
|
|
errorModel = new ErrorModel
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Message = exception.Message,
|
|
|
|
|
|
|
|
Description = exception.ToString()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
statusCode = HttpStatusCode.Conflict;
|
|
|
|
statusCode = HttpStatusCode.Conflict;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (exception is SQLiteException sqLiteException)
|
|
|
|
else if (exception is SQLiteException sqLiteException)
|
|
|
@ -91,18 +71,16 @@ namespace Prowlarr.Http.ErrorManagement
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (sqLiteException.Message.Contains("constraint failed"))
|
|
|
|
if (sqLiteException.Message.Contains("constraint failed"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
errorModel = new ErrorModel
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Message = exception.Message,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
statusCode = HttpStatusCode.Conflict;
|
|
|
|
statusCode = HttpStatusCode.Conflict;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path);
|
|
|
|
_logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
_logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path);
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await errorModel.WriteToResponse(response, statusCode);
|
|
|
|
await errorModel.WriteToResponse(response, statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|