Skip to content

Commit 149eecf

Browse files
Merge pull request #49 from contentstack/development
staging PR
2 parents 7a28d41 + 073b603 commit 149eecf

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## CHANGELOG
22

3-
## Version 0.8.0
3+
## Version 0.8.2
4+
### Date: 12th-January-2026
5+
### Improved error messages
6+
-
7+
8+
------------------------------------------------
9+
10+
## Version 0.8.1
411
### Date: 05th-January-2026
512
### Security Bug
613
- Fixed snyk security issues and updated license year

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ GEM
6868
simplecov_json_formatter (0.1.4)
6969
tzinfo (2.0.6)
7070
concurrent-ruby (~> 1.0)
71+
uri (1.1.1)
7172
webmock (3.11.3)
7273
addressable (>= 2.3.6)
7374
crack (>= 0.3.2)
@@ -76,6 +77,7 @@ GEM
7677

7778
PLATFORMS
7879
arm64-darwin-22
80+
arm64-darwin-24
7981

8082
DEPENDENCIES
8183
contentstack!

lib/contentstack/api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def self.fetch_retry(path, query=nil, count=0)
8282
sleep(retryDelay_in_seconds.to_i) #sleep method requires time in seconds as parameter
8383
response = fetch_retry(path, query, (count + 1))
8484
else
85-
raise Contentstack::Error.new(response) #Retry Limit exceeded
85+
raise Contentstack::Error.new(Contentstack::ErrorMessages.request_failed(response)) #Retry Limit exceeded
8686
end
8787
else
8888
to_render_content(response)
@@ -125,7 +125,7 @@ def self.send_request(path, q=nil)
125125
error_response = JSON.parse(response.string)
126126
error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
127127
error = error_response.merge(error_status)
128-
raise Contentstack::Error.new(error.to_s)
128+
raise Contentstack::Error.new(Contentstack::ErrorMessages.request_error(error))
129129
end
130130
end
131131

@@ -165,7 +165,7 @@ def self.send_preview_request(path, q=nil)
165165
error_response = JSON.parse(response.string)
166166
error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
167167
error = error_response.merge(error_status)
168-
raise Contentstack::Error.new(error.to_s)
168+
raise Contentstack::Error.new(Contentstack::ErrorMessages.request_error(error))
169169
end
170170
end
171171

lib/contentstack/client.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class Client
1010
attr_reader :region, :host
1111
# Initialize "Contentstack" Client instance
1212
def initialize(api_key, delivery_token, environment, options={})
13-
raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
14-
raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
15-
raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
16-
raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
17-
raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
18-
raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
13+
raise Contentstack::Error.new(Contentstack::ErrorMessages::API_KEY_INVALID) if api_key.class != String
14+
raise Contentstack::Error.new(Contentstack::ErrorMessages::API_KEY_REQUIRED) if api_key.empty?
15+
raise Contentstack::Error.new(Contentstack::ErrorMessages::DELIVERY_TOKEN_INVALID) if delivery_token.class != String
16+
raise Contentstack::Error.new(Contentstack::ErrorMessages::DELIVERY_TOKEN_REQUIRED) if delivery_token.empty?
17+
raise Contentstack::Error.new(Contentstack::ErrorMessages::ENVIRONMENT_INVALID) if environment.class != String
18+
raise Contentstack::Error.new(Contentstack::ErrorMessages::ENVIRONMENT_REQUIRED) if environment.empty?
1919
@region = options[:region].nil? ? Contentstack::Region::US : options[:region]
2020
# @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions
2121
@host = get_host_by_region(@region, options) # Added new method for custom host support with different regions
@@ -32,8 +32,8 @@ def initialize(api_key, delivery_token, environment, options={})
3232
"retryLimit"=> @retryLimit,
3333
"errorRetry" => @errorRetry
3434
}
35-
raise Contentstack::Error.new("Proxy URL Should not be Empty") if @proxy_details.present? && @proxy_details[:url].empty?
36-
raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
35+
raise Contentstack::Error.new(Contentstack::ErrorMessages::PROXY_URL_REQUIRED) if @proxy_details.present? && @proxy_details[:url].empty?
36+
raise Contentstack::Error.new(Contentstack::ErrorMessages::PROXY_PORT_REQUIRED) if @proxy_details.present? && @proxy_details[:port].empty?
3737
API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options)
3838
end
3939

lib/contentstack/error.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
module Contentstack
2+
# Centralized error messages for the SDK
3+
module ErrorMessages
4+
API_KEY_INVALID = "API Key is invalid. Provide a valid API Key and try again."
5+
API_KEY_REQUIRED = "API Key is required. Provide a valid API Key and try again."
6+
DELIVERY_TOKEN_INVALID = "Delivery Token is invalid. Provide a valid Delivery Token and try again."
7+
DELIVERY_TOKEN_REQUIRED = "Delivery Token is required. Provide a valid Delivery Token and try again."
8+
ENVIRONMENT_INVALID = "Environment is invalid. Provide a valid Environment and try again."
9+
ENVIRONMENT_REQUIRED = "Environment is required. Provide a valid Environment and try again."
10+
PROXY_URL_REQUIRED = "Proxy URL is required. Provide a valid Proxy URL and try again."
11+
PROXY_PORT_REQUIRED = "Proxy Port is required. Provide a valid Proxy Port and try again."
12+
13+
def self.request_failed(response)
14+
"The request could not be completed due to #{response}. Review the details and try again."
15+
end
16+
17+
def self.request_error(error)
18+
"The request encountered an issue due to #{error}. Review the details and try again."
19+
end
20+
end
21+
222
class Error < StandardError
323
def initialize(msg="Something Went Wrong.")
424
super

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.8.1"
2+
VERSION = "0.8.2"
33
end

0 commit comments

Comments
 (0)