Closed Wrufesh closed 1 year ago
Hi @Wrufesh, Can you please add the actual error message as well? I want to compare it with the pre-processed exception.
Hi @Wrufesh, Can you please add the actual error message as well? I want to compare it with the pre-processed exception.
Sorry for confusing you. I mean the following:
Instead of the following code:
def create_workspace(self, workspace: str):
"""
Create a new workspace in geoserver.
The geoserver workspace url will be same as the name of the workspace.
"""
try:
url = "{}/rest/workspaces".format(self.service_url)
data = "<workspace><name>{}</name></workspace>".format(workspace)
headers = {"content-type": "text/xml"}
r = self._requests("post", url, data=data, headers=headers)
if r.status_code == 201:
return "{} Workspace {} created!".format(r.status_code, workspace)
else:
raise GeoserverException(r.status_code, r.content)
except Exception as e:
raise Exception(e)
Can we write just:
def create_workspace(self, workspace: str):
url = "{}/rest/workspaces".format(self.service_url)
data = "<workspace><name>{}</name></workspace>".format(workspace)
headers = {"content-type": "text/xml"}
r = self._requests("post", url, data=data, headers=headers)
if r.status_code == 201:
return "{} Workspace {} created!".format(r.status_code, workspace)
else:
raise GeoserverException(r.status_code, r.content)
You mean to remove try, except
block right? Sounds good to me. Please feel free to send PR.
Hi @iamtekson I created a PR for this issue. If possible, after you except you should do a public release, a new patch, because the current build, that you can download with pip is failing on some requests, which are already fixed on the master branch.
Hi @szokejokepu, Thanks for the PR. I will review it soon.
Hi,
I just started using geoserver-rest for one of my script which does some preprocessing of dataset and uploads them to geoserver.
I was interested in organizing my uploads with proper namespace. So in case the workspace "ADCD" already exist and I do:
geo.create_workspace(workspace='ABCD')
I get:
Now in order to capture status code and message from structure html I have to do some text processing.
I was wondering if we would just throw GeoserverException we could have got status_code and could parse html message easily.
Well it is still possible to achieve by preprocessing the exception message.