I am running Invoke-Webrequest to upload a file to Nexus server the first time when I run it, works fine but when I re-run it, fails because the file already exists and Nexus is set to not allowing overwriting existing files. What I need is that when I run Invoke-Webrequest when the file I'm trying to upload already exists, it just simply returns 400 bad request. How can I get more detailed error message so that I know what the problem is with the request?
try {
// invoke-webrequest
}
catch {
throw $_.Exception.Response
}