# Class RESTErrorResponse

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.system.RESTErrorResponse](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTErrorResponse.md)

This class represents a REST error response that is compliant with
[RFC 9457](https://www.rfc-editor.org/rfc/rfc9457). It can only be instantiated using the
`createError` methods in [RESTResponseMgr](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTResponseMgr.md).

Here is an example:

```

var error = RESTResponseMgr.createError(400);
error.custom.foo = "bar";
error.render();
```

The above script would result in an HTTP response with status code 400 and the following body:

```

{
    "type": "https://api.commercecloud.salesforce.com/documentation/error/v1/custom-errors/bad-request",
    "c_foo": "bar"
}
```

NOTE:

- Custom attributes are rendered with "c\_" prefix as shown in the example above.
- Rendering works as described in [JSON.stringify(Object)](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.JSON.md#stringifyobject).

## Property Summary

| Property                                                                                                                                 | Description                                                                  |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [custom](#custom): [CustomAttributes](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.object.CustomAttributes.md) `(read-only)` | Returns all the custom attributes associated with the error response object. |

## Constructor Summary

This class does not have a constructor, so you cannot create it directly.

## Method Summary

| Method                                                                                                        | Description                                                                                                                                                                                                                          |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [getCustom](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTErrorResponse.md#getcustom)() | Returns all the custom attributes associated with the error response object.                                                                                                                                                         |
| [render](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTErrorResponse.md#render)()       | Sends the [RESTErrorResponse](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTErrorResponse.md) object as an HTTP error response to the client, adhering to  [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457). |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Property Details

### custom

- custom: [CustomAttributes](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.object.CustomAttributes.md) `(read-only)`
  - : Returns all the custom attributes associated with the error response object. The attributes are stored for the
    lifetime of the error response object.

***

## Method Details

### getCustom()

- getCustom(): [CustomAttributes](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.object.CustomAttributes.md)
  - : Returns all the custom attributes associated with the error response object. The attributes are stored for the
    lifetime of the error response object.

    **Returns:**

    - All the custom attributes associated with the error response object.

***

### render()

- render(): void
  - : Sends the [RESTErrorResponse](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.system.RESTErrorResponse.md) object as an HTTP error response to the client, adhering to
    [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457). This method sets the "Content-Type" header to
    "application/problem+json", HTTP Status Code to statusCode attribute and constructs the body from type, title,
    detail and custom attributes of the object. Custom attributes are rendered with "c\_" prefix to the attribute
    name.

    **Throws:**

    - IllegalStateException - If the RESTErrorResponse object is already rendered.
    - Exception - If there is an error while serializing the RESTErrorResponse object.

***
