 			return
 		}
 		
+		if let remaining = rateLimitRemaining, let reset = rateLimitReset, remaining < 1 && reset > Date() {
+			completion(.failure(RedditFeedProviderError.rateLimitExceeded))
+			return
+		}
+		
 		let url = "\(Self.apiBase)\(api)"
 
 		var expandedParameters = parameters

import RSWeb

public enum RedditFeedProviderError: LocalizedError {
	case unknown
	
	public var localizedDescription: String {
		switch self {
		case .unknown:
			return NSLocalizedString("A Reddit Feed Provider error has occurred.", comment: "Unknown error")
		}

			switch result {
			case .success(let response):
				
//				let jsonString = String(data: response.data, encoding: .utf8)
//				let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("reddit.json")
//				print("******** writing to: \(url.path)")
//				try? jsonString?.write(toFile: url.path, atomically: true, encoding: .utf8)

				if let remaining = response.response.value(forHTTPHeaderField: "X-Ratelimit-Remaining") {
					self.rateLimitRemaining = Int(remaining) ?? 0
				}
				if let reset = response.response.value(forHTTPHeaderField: "X-Ratelimit-Reset") {
					self.rateLimitReset = Date(timeIntervalSinceNow: Double(reset) ?? 0)
				}

				let decoder = JSONDecoder()
				
