impossible to check if dataset exists without parsing message string of the response

Open
#1,893 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript

Research direction

Start by comparing the v3 and v4 GET /Datasets/{pid} responses with the documented dataset and invalid-endpoint cases. Define a stable way for clients to distinguish a missing dataset from another 404 without parsing a version-dependent message, then verify that behavior across the cited API versions and examples.

Written by the indexing model from the issue text.

Description

Summary

In the loopback implementation of scicat there were endpoint /exists to check if dataset exists.
After switching to nestjs it was recommended to use /datasets/{pid} so when dataset does not exist it returns 200 with empty content. However, in the resent implementation the REST API behaviour unfortunately was changed and after implementing https://github.com/SciCatProject/scicat-backend-next/issues/553 (similarly https://github.com/SciCatProject/scicat-backend-next/issues/842) it returns 404 with same content message.
That causes troubles for client to check which is the case if dataset does not exist or if other 404 error has been sent (e.g. wrong endpoint string). The only possible way is to parse response message which can easily change in the future e.g. v3 message is different then v4.

Steps to Reproduce

To reproduce the issue e.g in scicat 4.16.0

import requests

# v3
r = requests.get(
    url="http://localhost:3000/api/v3/Datasets/1111111",
)
print(r.content)
# 
# b'{"message":"dataset: 111111111 not found","error":"Not Found","statusCode":404}'
# 

# v4
r = requests.get(
    url="http://localhost:3000/api/v4/Datasets/1111111",
)
print(r.content)
# 
# b'{"message":"dataset: null not found","error":"Not Found","statusCode":404}'
# 

#endpoint is wrong
r = requests.get(
    url="http://localhost:3000/api/v4/Dataset/1111111",
)
print(r.content)
# 
# b'{"message":"Cannot GET /api/v3/dataset/111111111?access_token=eyJ6g","error":"Not Found","statusCode":404}
# 

Expected behavior

I would expect that to check is dataset exists you don't have to parse a message string which changing from version to version.
I would expect that REST API don't know change in the same version API (it was done between 4.5.0 and 4.16.0 in v3)

Dominant language
TypeScript
Stars
27
Forks
37
Avg merge
17h 32m
Merged PRs (30d)
38

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SciCatProject/backend

All issues in SciCatProject/backend

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.