0

We are using SharePoint 2016 for storage and retrieval of files. And using java httpclient class to do it. Now we are using following API to check whether folder is already present.

String folderURI = "/_api/Web/GetFolderByServerRelativeUrl('" + "/<document library/folderpath>" + "')";

e.g : folderpath = test1/type/2007

Following is the code to contact SharePoint and get it's response.

HttpGet httpget = new HttpGet(finalURL);  
httpget.setHeader("Content-Type", "application/octet-stream");  
httpget.setHeader("X-HTTP-Method", requestMethod);  
httpget.setHeader("Cookie", "rtFa="YqLvkl";FedAuth="uZnxt");

response = httpClient.execute((HttpUriRequest) httpget);

If the folder already present, I'm getting 200 ok as response, which is correct. But if folder not present, I'm getting 500 internal server error. instead of this,I should get 404 Not Found. What am I missing. how come for the same API, I'm getting one correct response(folder present 200 ok) and one internal server error(folder not present 500).

rrm
  • 9
  • 2

1 Answers1

0

4xx errors are client errors; 5xx errors are server errors.

4xx errors mean you (the client) have made a mistake with the way you submitted your request. 5xx errors mean the server failed to fulfill an apparently valid request.

A response of 404 (Page Not Found) would indicate that the requested URI is itself invalid/doesn't currently exist. This would make sense as a response if you were trying to access the direct path of a folder that doesn't exist (instead of invoking a web service through the /_api/Web/ URI).

Your requested URI is a valid web service call, so 404 Not Found would be not be an appropriate response.

500 (Internal Server Error) is the generic response that indicates that the web server ran into an error while attempting to perform an operation.

In this case the error is caused by the web service attempting to retrieve a folder that does not exist.

Thriggle
  • 7,009
  • 2
  • 26
  • 37
  • hi Thriggle, if resource not found(folder/files), then sharepoint response is 404 not found. if present, it's 200 ok. we used sharepoint 2013 before this, and we got this response.But in sharepoint 2016, file search giving same response(200,404), but folder response differs(200,500). so you mean 500 is correct response?? – rrm Jun 15 '17 at 05:43