-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SubscriptionClient.subscriptions.get SubscriptionNotFound Error is in the wrong format #33035
Comments
@xirzec
For modular and RLC, we have already fixed it in core client rest here https://github.com/Azure/azure-sdk-for-js/pull/27867/files and in codegen here Azure/autorest.typescript#1997 |
@qiaozha Maybe I'm misunderstanding something here, but isn't the problem that the spec for this API doesn't have a default response shape? Since that causes us to throw on this line:
But when the spec does have at least a default handler we set the code and message here:
Perhaps we could do something smarter here, like see if the parsedBody is a "standard" error shape, even if we don't have the original message? I do agree there is some risk of folks currently working around this by doing JSON.parse of the message though. |
Yes we could try some heuristic in deserializationPolicy.ts to help the experience. Let me take a look into this. |
…ult body mapper Currently, when we receive an error response and there is no default body mapper, we immediately throw a RestError without further inspecting the response body. It's ideal for operation specifications to define a default mapper for unexpected responses. However, some services did not implement this leading to issues like Azure#33035 where the error message contains a JSON string of the error object, and the error code is undefined. This PR modifies the behavior to look into parsedBody if it has an 'error' property that contains both 'code' and 'message' properties, improving the developer experience in this scenario.
…ult body mapper Currently, when we receive an error response and there is no default body mapper, we immediately throw a RestError without further inspecting the response body. It's ideal for operation specifications to define a default mapper for unexpected responses. However, some services did not implement this leading to issues like Azure#33035 where the error message contains a JSON string of the error object, and the error code is undefined. This PR modifies the behavior to look into parsedBody if it has an 'error' property that contains both 'code' and 'message' properties, improving the developer experience in this scenario.
@xirzec I see your point, I will contact the service team to add error response here. |
Describe the bug
When you use
SubscriptionClient.subscriptions.get(subscriptionId)
on a subscription that does not exist, An error is thrownthe TS typing makes it seem like
error.code === 'SubscriptionNotFound'
anderror.message = "The subscription '...' was not found."
but instead what you get is
error.code === undefined
anderror.message = {error:"code": "SubscriptionNotFound", message: "The subscription '...' was not found."},
which goes against the Typing of message:string and means in TS you cannot check for 'SubscriptionNotFound' without TS shenanigans.To Reproduce
Steps to reproduce the behavior:
example:
const client = new SubscriptionClient(CREDENTIALS) client.subscriptions.get(FAKE_ID)
Expected behavior
I would expect the returned error to have
error.code === 'SubscriptionNotFound'
anderror.message = "The subscription '...' was not found."
The text was updated successfully, but these errors were encountered: