What is sn_ws_err API and how to implement it's methods?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello,
Can anyone explain what is sn_ws_err API and how to implement it's methods?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Buddy,
sn_ws_err is a ServiceNow server-side utility used in Scripted REST APIs to return proper HTTP errors in a clean, consistent way. It helps you send the correct status code 400, 401, 404, etc.... along with a meaningful error message instead of manually building responses.
You typically use it inside a Scripted REST resource, not client-side.
Common you can use it:
Set an error on the response (most common):
response.setError(new sn_ws_err.NotFoundError('Record not found'));
return;Throws an error:
throw new sn_ws_err.BadRequestError('Missing required parameter');Common error types include:
BadRequestError (400)
UnauthorizedError (401 )
ForbiddenError (403)
NotFoundError (404)
If you need a custom status or message, you can use like ServiceError:
var err = new sn_ws_err.ServiceError();
err.setStatus(409);
err.setMessage('Conflict');
err.setDetail('Record already exists');
return err;Basically, sn_ws_err is the recommended way to handle errors in Scripted REST APIs so consumers get clear, standard HTTP responses instead of generic failures.
@ShouryaD - Please mark Accepted Solution and Thumbs Up if you find Helpful 🙂
