Merge branch 'fix/schema-drafts-active-200-when-empty' into 'main'
fix(schema-drafts): /drafts/active returns 200+null instead of 404 (no console spam) See merge request 2-6/2-6-4/terravault/ordinis!199
This commit is contained in:
+15
-6
@@ -169,15 +169,24 @@ public class SchemaDraftController {
|
||||
/**
|
||||
* Convenience endpoint: фронт хочет ОДИН query'ом узнать "есть ли active
|
||||
* draft на этом dict'е и в каком он state'е". Returns 200 с draft body
|
||||
* либо 404 если нет active.
|
||||
* либо 200 с {@code null} если активного draft нет.
|
||||
*
|
||||
* <p><b>Why 200 + null instead of 404:</b> "no active draft" — это normal
|
||||
* state, не error condition. Раньше возвращали 404 {@code no_active_draft},
|
||||
* frontend silently mapped to null, но browser console всё равно logs 4xx
|
||||
* network failures на каждый poll (refetchInterval=20s + invalidate after
|
||||
* mutations). Spam'ило console. 200 + null body = clean console + same
|
||||
* frontend behavior.
|
||||
*
|
||||
* <p>Frontend (queries.ts dictActiveSchemaDraftQuery) сохраняет 404→null
|
||||
* fallback для backward compat и robustness — если кто-то откатит этот
|
||||
* change или старый client с новым backend ещё не deployed.
|
||||
*/
|
||||
@GetMapping("/api/v1/dictionaries/{name}/drafts/active")
|
||||
public SchemaDraftResponse active(@PathVariable String name) {
|
||||
DictionarySchemaDraft draft = draftService.findActive(name).orElseThrow(() ->
|
||||
cloud.nstart.terravault.ordinis.restapi.error.OrdinisException.notFound(
|
||||
"no_active_draft",
|
||||
"У справочника " + name + " нет активного draft'а."));
|
||||
return SchemaDraftResponse.from(draft, name);
|
||||
return draftService.findActive(name)
|
||||
.map(d -> SchemaDraftResponse.from(d, name))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/** Single draft по id (drilling в reviewer queue). */
|
||||
|
||||
Reference in New Issue
Block a user