Skip to content

Commit

Permalink
Align ProwlarrErrorPipeline with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Jul 4, 2023
1 parent 57efa6d commit 02a3c1b
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions src/Prowlarr.Http/ErrorManagement/ProwlarrErrorPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,17 @@ public async Task HandleException(HttpContext context)
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
var exception = exceptionHandlerPathFeature?.Error;

_logger.Warn(exception);

var statusCode = HttpStatusCode.InternalServerError;
var errorModel = new ErrorModel
{
Message = exception.Message,
Description = exception.ToString()
Message = exception?.Message,
Description = exception?.ToString()
};

if (exception is ApiException apiException)
{
_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);
statusCode = apiException.StatusCode;
}
Expand All @@ -59,30 +54,15 @@ public async Task HandleException(HttpContext context)
}
else if (exception is NzbDroneClientException clientException)
{
errorModel = new ErrorModel
{
Message = exception.Message,
Description = exception.ToString()
};
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;
}
else if (exception is ModelConflictException conflictException)
else if (exception is ModelConflictException)
{
_logger.Error(exception, "DB error");
errorModel = new ErrorModel
{
Message = exception.Message,
Description = exception.ToString()
};
statusCode = HttpStatusCode.Conflict;
}
else if (exception is SQLiteException sqLiteException)
Expand All @@ -91,18 +71,16 @@ public async Task HandleException(HttpContext context)
{
if (sqLiteException.Message.Contains("constraint failed"))
{
errorModel = new ErrorModel
{
Message = exception.Message,
};
statusCode = HttpStatusCode.Conflict;
}
}

_logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path);
}

_logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path);
else
{
_logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path);
}

await errorModel.WriteToResponse(response, statusCode);
}
Expand Down

0 comments on commit 02a3c1b

Please sign in to comment.