Make RestClient handle 404 like all other failure status codes
parkerault opened this issue · 2 comments
parkerault commented
Issue Description
It drives me absolutely batty, especially when using typescript, that response.result is nullable only in the special case of a 404. What is the reasoning behind 404 being the only failure status code that doesn't throw in the RestClient? This also makes it impossible to send a payload with a 404: #202.
Expected behaviour
const client = new RestClient("myAPI", "https://www.example.com/api");
const doSomethingWithResult = (result: IEntity) => console.log(result);
let entity: IEntity;
try {
const response = client.get<IEntity>("/entity");
doSomethingWithResult(response.result);
} catch (e) {
console.error(e);
}
Actual behaviour
const client = new RestClient("myAPI", "https://www.example.com/api");
const doSomethingWithResult = (result: IEntity) => console.log(result);
try {
const response = client.get<IEntity>("/entity");
if (response.result !== null) {
doSomethingWithResult(response.result);
} else {
throw new Error("Opps, I was told it was okay but it's actually an error!")
}
} catch (e) {
console.error(e)
}
I work around this by creating helper functions, but it seems like that shouldn't be necessary.
github-actions commented
This issue has had no activity in 90 days. Please comment if it is not actually stale
john8329 commented
This made me waste an hour of troubleshooting, and it's a nonstandard behaviour. It's very relevant and I see no rationale for returning no body. The error is semantic, but more details might needed.