<TRCErrorHandler> Protocol Reference

TRCErrorHandler used to compose custom NSError from response body when request finished with error status code (For example 4xx or 5xx codes), or when response body contains error. More...

Inheritance diagram for <TRCErrorHandler>:

Instance Methods

(NSError *) - errorFromResponseBody:headers:status:error:
 This method returns custom NSError composed from response body. More...
 
(NSString *) - errorValidationSchemaName
 Specify schema name to validate bodyObject before processing. More...
 
(BOOL) - isErrorResponseBody:headers:status:
 Implement your body checking for error. More...
 

Detailed Description

TRCErrorHandler used to compose custom NSError from response body when request finished with error status code (For example 4xx or 5xx codes), or when response body contains error.

Method Documentation

◆ errorFromResponseBody:headers:status:error:()

- (NSError *) errorFromResponseBody: (id)  bodyObject
headers: (NSDictionary *)  headers
status: (TRCHttpStatusCode statusCode
error: (NSError **)  error 

This method returns custom NSError composed from response body.

Body represented by 'bodyObject' argument.

bodyObject comes through serialization, validation, conversions (using TRCObjectMapper and TRCValueTransformer) before appears here.

See more information about bodyObject in TRCRequest.responseProcessedFromBody:headers:status:error:.

You also may want to specify schema for validation. Check errorValidationSchemaName method. If schema specified, then bodyObject validation failed, this method will not be called, and general error returns at top-level call

See also
TRCRequest.responseProcessedFromBody:headers:status:error:
TyphoonRestClient.errorHandler

◆ errorValidationSchemaName()

- (NSString *) errorValidationSchemaName
optional

Specify schema name to validate bodyObject before processing.

If this method not implemented then ClassName.response.{format} name assumed

◆ isErrorResponseBody:headers:status:()

- (BOOL) isErrorResponseBody: (id)  bodyObject
headers: (NSDictionary *)  headers
status: (TRCHttpStatusCode statusCode 
optional

Implement your body checking for error.

This is required when your API uses some status codes inside response body, instead of HTTP status codes.

Note that bodyObject is raw object, which goes directly from TRCConnection. Without applying any schema.

The goal of this method is just say that body looks like error or not.

Examples: If each response contains status field, then you'll check for that code in that method { "status": 200 } or if each response contains success boolean field, you can check it here { "success": true }