Skip to content

Commit c2dbaec

Browse files
authored
Merge pull request #191 from contentstack/fix/branch
fix: added branch set via the stack config
2 parents f858c72 + 2a07f76 commit c2dbaec

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

Contentstack.Core.Tests/Integration/Taxonomy/TaxonomyLocalisationTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public async Task Find_Terms_WithLocaleAndFallback_ReturnsTerms()
146146
LogAssert("Verifying response");
147147
Assert.NotNull(result);
148148
Assert.NotNull(result.Items);
149-
// Fallback means we should get at least as many terms as without fallback
150149
Assert.True(result.Items.Any());
151150
}
152151

Contentstack.Core/Models/Taxonomy.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ public async System.Threading.Tasks.Task<T> Fetch<T>(string locale = null)
126126
mainJson["locale"] = locale;
127127

128128
var handler = new HttpRequestHandler(Stack);
129-
var branch = Stack.Config?.Branch ?? "main";
130129
var result = await handler.ProcessRequest(
131130
_Url, headerAll, mainJson,
132-
Branch: branch,
131+
Branch: Stack.Config.Branch,
133132
timeout: Stack.Config.Timeout,
134133
proxy: Stack.Config.Proxy
135134
);
@@ -142,7 +141,13 @@ public async System.Threading.Tasks.Task<T> Fetch<T>(string locale = null)
142141
}
143142
catch (Exception ex)
144143
{
145-
throw TaxonomyException.CreateForProcessingError(ex);
144+
var contentstackError = GetContentstackError(ex);
145+
throw new TaxonomyException(contentstackError.Message, ex)
146+
{
147+
ErrorCode = contentstackError.ErrorCode,
148+
StatusCode = contentstackError.StatusCode,
149+
Errors = contentstackError.Errors
150+
};
146151
}
147152
}
148153

Contentstack.Core/Models/Term.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ public async Task<T> Fetch<T>(string locale = null, bool includeFallback = false
6464
}
6565
catch (Exception ex)
6666
{
67-
throw TaxonomyException.CreateForProcessingError(ex);
67+
var contentstackError = Taxonomy.GetContentstackError(ex);
68+
throw new TaxonomyException(contentstackError.Message, ex)
69+
{
70+
ErrorCode = contentstackError.ErrorCode,
71+
StatusCode = contentstackError.StatusCode,
72+
Errors = contentstackError.Errors
73+
};
6874
}
6975
}
7076

@@ -95,7 +101,13 @@ public async Task<T> Locales<T>()
95101
}
96102
catch (Exception ex)
97103
{
98-
throw TaxonomyException.CreateForProcessingError(ex);
104+
var contentstackError = Taxonomy.GetContentstackError(ex);
105+
throw new TaxonomyException(contentstackError.Message, ex)
106+
{
107+
ErrorCode = contentstackError.ErrorCode,
108+
StatusCode = contentstackError.StatusCode,
109+
Errors = contentstackError.Errors
110+
};
99111
}
100112
}
101113

@@ -126,7 +138,13 @@ public async Task<T> Ancestors<T>()
126138
}
127139
catch (Exception ex)
128140
{
129-
throw TaxonomyException.CreateForProcessingError(ex);
141+
var contentstackError = Taxonomy.GetContentstackError(ex);
142+
throw new TaxonomyException(contentstackError.Message, ex)
143+
{
144+
ErrorCode = contentstackError.ErrorCode,
145+
StatusCode = contentstackError.StatusCode,
146+
Errors = contentstackError.Errors
147+
};
130148
}
131149
}
132150

@@ -157,7 +175,13 @@ public async Task<T> Descendants<T>()
157175
}
158176
catch (Exception ex)
159177
{
160-
throw TaxonomyException.CreateForProcessingError(ex);
178+
var contentstackError = Taxonomy.GetContentstackError(ex);
179+
throw new TaxonomyException(contentstackError.Message, ex)
180+
{
181+
ErrorCode = contentstackError.ErrorCode,
182+
StatusCode = contentstackError.StatusCode,
183+
Errors = contentstackError.Errors
184+
};
161185
}
162186
}
163187

@@ -176,10 +200,9 @@ private async Task<string> ExecuteRequest(string url, Dictionary<string, object>
176200
mainJson[param.Key] = param.Value;
177201

178202
var handler = new HttpRequestHandler(_stack);
179-
var branch = _stack.Config?.Branch ?? "main";
180203
return await handler.ProcessRequest(
181204
url, headerAll, mainJson,
182-
Branch: branch,
205+
Branch: _stack.Config.Branch,
183206
timeout: _stack.Config.Timeout,
184207
proxy: _stack.Config.Proxy
185208
);

Contentstack.Core/Models/TermQuery.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Threading.Tasks;
45
using Contentstack.Core.Internals;
56
using Newtonsoft.Json.Linq;
@@ -87,18 +88,17 @@ public async Task<ContentstackCollection<T>> Find<T>()
8788
mainJson[param.Key] = param.Value;
8889

8990
var handler = new HttpRequestHandler(_stack);
90-
var branch = _stack.Config?.Branch ?? "main";
9191
var result = await handler.ProcessRequest(
9292
Url, headerAll, mainJson,
93-
Branch: branch,
93+
Branch: _stack.Config.Branch,
9494
timeout: _stack.Config.Timeout,
9595
proxy: _stack.Config.Proxy
9696
);
9797

9898
var jObject = JObject.Parse(result);
9999
var terms = jObject.SelectToken("$.terms")?.ToObject<IEnumerable<T>>(_stack.Serializer);
100100
var collection = jObject.ToObject<ContentstackCollection<T>>(_stack.Serializer);
101-
collection.Items = terms ?? new List<T>();
101+
collection.Items = terms ?? Enumerable.Empty<T>();
102102
return collection;
103103
}
104104
catch (TaxonomyException)
@@ -107,7 +107,13 @@ public async Task<ContentstackCollection<T>> Find<T>()
107107
}
108108
catch (Exception ex)
109109
{
110-
throw TaxonomyException.CreateForProcessingError(ex);
110+
var contentstackError = Taxonomy.GetContentstackError(ex);
111+
throw new TaxonomyException(contentstackError.Message, ex)
112+
{
113+
ErrorCode = contentstackError.ErrorCode,
114+
StatusCode = contentstackError.StatusCode,
115+
Errors = contentstackError.Errors
116+
};
111117
}
112118
}
113119
}

0 commit comments

Comments
 (0)