Error Handling and HTTP Response Headers in SuiteScript

Error handling in SuiteScript includes managing read-only properties and understanding HTTP response headers.

·2 min read·View Oracle Docs

The handling of errors and HTTP response headers in SuiteScript is essential for developers working with both client and server scripts. This article covers key error codes and the implications of HTTP headers.

How Do HTTP Response Headers Work?

HTTP response headers deliver additional information when making HTTP requests. Each header consists of a case-insensitive name followed by a colon and its corresponding value.

Types of HTTP Response Headers

For client scripts, response header values can be a list of strings due to the ability to handle multiple headers with the same name. In server SuiteScript, however, each header value is a single string, preserving only the first instance if multiple headers share the same name.

What Are Common Error Codes?

READ_ONLY_PROPERTY

  • Thrown If: You attempted to edit a read-only property.

Code Sample: Accessing Response Headers

The following code snippet demonstrates accessing response headers, showcasing both client and server SuiteScript.

suitescript
1var response = https.get({
2 url: 'https://www.testwebsite.com'
3});
4log.debug({
5 title: 'Client Response Header',
6 details: response.headers
7});

In this example, the headers are logged for debugging purposes. For instance, while a client script can access multiple values for a header:

suitescript
response.headers["cache-control"]
// Output: ["no-cache", "no-store"]

A server script can only retrieve the first value:

suitescript
response.headers["cache-control"]
// Output: "no-cache"

Best Practices for Handling HTTP Headers

  • Case Sensitivity: HTTP headers are defined as case-insensitive. It is recommended to retrieve them in lower-case, e.g., response.headers["content-type"].
  • Header Compatibility: Each header may be represented in multiple cases for compatibility. Examples include:
    • `

Frequently Asked Questions (4)

How do client and server SuiteScripts differ in handling HTTP response headers?
In client SuiteScripts, response header values can be a list of strings, allowing for multiple headers with the same name. However, in server SuiteScripts, each header value is a single string, which preserves only the first instance if multiple headers share the same name.
What error code is thrown if I attempt to edit a read-only property in SuiteScript?
If you attempt to edit a read-only property in SuiteScript, the `READ_ONLY_PROPERTY` error code is thrown.
What is the recommended practice for retrieving HTTP headers concerning case sensitivity?
It is recommended to retrieve HTTP headers in lower-case because they are defined as case-insensitive. For instance, use 'response.headers["content-type"]' to ensure compatibility.
Can a server script access multiple values for the same HTTP response header?
No, a server script can only retrieve the first value of an HTTP response header if there are multiple headers with the same name.
Source: Errors Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →