Search.../

badRequest( )

Returns a response with status code 400 (Bad Request) and the information from the options parameter.

Description

The badRequest() function creates a response with the status code 400 (Bad Request).

Optionally, the badRequest() function can take a WixHttpFunctionResponseOptions object which is used to specify the response's body and headers. If the object contains a status it will be ignored.

Use the badRequest() function to create a response to return from an HTTP function. A 400 (Bad Request) response is usually used to indicate the request was unsuccessful because of a client error, such as a request using the incorrect syntax.

Syntax

function badRequest(options: WixHttpFunctionResponseOptions): WixHttpFunctionResponse

badRequest Parameters

NAME
TYPE
DESCRIPTION
options

WixHttpFunctionResponseOptions

The response options.

Returns

Was this helpful?

Create a 400 (Bad Request) response

Code Example

Copy Code
1// In http-functions.js
2
3import {badRequest} from 'wix-http-functions';
4
5export function use_myFunction(request) {
6
7 return badRequest();
8}
Create a 400 (Bad Request) response

Code Example

Copy Code
1// In http-functions.js
2
3import {badRequest} from 'wix-http-functions';
4
5export function use_myFunction(request) {
6
7 let options = {
8 body: {
9 "error": "The request must contain the 'X' parameter."
10 },
11 headers: {
12 "Content-Type": "application/json"
13 }
14 };
15
16 return badRequest(options);
17}