//
//  DOWebErrorFilter.h
//  DOCore
//
//  Created by Ben Dolman on 3/5/15.
//
//

#import <Foundation/Foundation.h>
#import <DOCore/DOHTTPResponseFilter.h>

/**
 * A filter for custom handling of Day One web service errors.
 *
 * The Day One web service will, in some cases, return a JSON payload when there is an error
 * that looks something like this:
 * {
 *    code: 400,
 *    error: 'Invalid user object',
 *    fields: { 'password' : 'Password must be at least 5 chars' }
 * }
 * 
 * This filter handles this custom response and creates an NSError object to represent it.
 * This should be the first filter in your response pipeline.
 */
@interface DOWebErrorFilter : NSObject <DOHTTPResponseFilter>

+ (instancetype)defaultFilter;

/**
 * Initializes the filter with a class that will be used for field mapping (if present in the response).
 * This class must be subclass of MTLModel and conform to MTLJSONSerializing.
 */
- (instancetype)initWithMantleJSONClass:(Class)class;

/**
 * Initializes the filter with a custom field map.
 */
- (instancetype)initWithFieldMapDictionary:(NSDictionary *)dict;

@end

