Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Overview

Sets the expected status code to verify request

RestRequest myRestRequest.Expect(status: string)

Arguments

string status
Status code

Remarks

If this method is not used, default expected status codes are used.

This method can be called multiple times to allow different status codes.

Status Code must be one of the following values from "Status" column;

Example

var client, request;
client = $Rest.Create(restUrl + '/employers/60ec35c7-7595-4c3a-bb12-f6c8a3be953a/payrun/Year2019/Monthly');

request = client.Request();
request.Method = 'Put';
request.AddHeader('Content-Type', contentType);
request.AddHeader('Authorization', 'Basic ' + authorizationCode);

console.info(request.Expect('Created').Put().ToJson());

Example

Expecting more than one status

var client, request, response;
client = $Rest.Create(restUrl + '/employers/60ec35c7-7595-4c3a-bb12-f6c8a3be953a/payrun/Year2019/Monthly');

request = client.Request();
request.Method = 'Put';
request.AddHeader('Content-Type', contentType);
request.AddHeader('Authorization', 'Basic ' + authorizationCode);
request.Expect('Created');
request.Expect('BadRequest');

try {
    console.info('Calling ' + client.Url);
     
    response = request.Put().ToJson();
 
    if(response.status == 'BadRequest') {
        console.error(response.error);
        throw response;
    }
 
    console.info(response.status);
}
catch (err) {
    throw err.error;
}
  • No labels