badges / badges/shields

Add not found schema to base services

Open
#2,632 5 comments 0 reactions 0 assignees View on GitHub
core
Dominant language
JavaScript
Stars
27.2k
Forks
5.6k
Avg merge
1d 8h
Merged PRs (30d)
46

Description

This code is from the clojar badge:

```js
if (Object.keys(json).length === 0) {
/* Note the 'not found' response from clojars is:
status code = 200, body = {} */
throw new NotFound()
}
```

We have a bunch of other similar examples, where the schema is written to accommodate the not found case, and then there's code written to detect the alternate case and throw an error.

This responsibility is a kind of schema validation. We'd have clearer guarantees, particularly in the "found" case, if this responsiblity were delegated to Joi.

A really clean way to express this would be to optionally provide two schemas to `_requestJson` and friends. One would be the `schema` for the success case (like what we're passing now) and the other a `notFoundSchema`. If the `notFoundSchema` matches, we automatically throw `NotFound`, using the 404 error message.

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Start by locating `_requestJson` and related base-service request helpers, then inspect existing schemas that handle not-found responses; done means an optional `notFoundSchema` is supported and matching responses throw `NotFound` with the 404 error message while success responses retain schema validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.