Hi
I have created Script Runner Rest End point.
For the success case, I am sending ok response with JSON as shown below
return Response.ok(new JsonBuilder([success: success]).toString()).build();
For the failure case, I want to send not.ok response. May be 404 status code with JSON error message.
Can anyone please tell how to do it? Is there any method for that?
Hi Nallusamy,
To return a failed response, you could try someting like:
return Response.status(404).entity("NOT-OK").type(acceptType).build()
Please note, this sample is not 100% exact to your environment. Hence you will need to make the required changes.
Hope this helps to solve your question :)
Kind Regards,
Ram
Thanks @Ram Kumar Aravindakshan _Adaptavist_
return Response.status(404).entity("${sourceIssueKey} - Source JIRA Key does not exist.").build();
It just returns string given in entity. What should I do to get status code as well?
Curl command:
curl -X POST -H "Content-type: text/json" -u nnallusamy: --data "@linkIssueInput.json" https://devjira.athenahealth.com/rest/scriptrunner/latest/custom/linkJiraIssue
Result:
"ACRK-86888 - Source JIRA Key does not exist."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Ram Kumar Aravindakshan _Adaptavist_
return Response.status(404).entity("${sourceIssueKey} - Source JIRA Key does not exist.").build();
What should i do to get the status code along with entity message?
curl -X POST -H "Content-type: text/json" -u nallu @123 --data "@linkIssueInput.json" https://devjira.athenahealth.com/rest/scriptrunner/latest/custom/linkJiraIssue
"ACRK-86888 - Source JIRA Key does not exist."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nallusamy,
From your requirement, you could include the status code in the message itself, for example:-
return Response.status(404).entity("404 - ${sourceIssueKey} - Source JIRA Key does not exist.").build()
Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.