Skip to content

Commit

Permalink
[notification hubs] Update XML Error parsing for Issue #25914 (#26209)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/notification-hubs

### Issues associated with this PR

- #25914

### Describe the problem that is addressed by this PR

Updates code to fix the error code parsing for XML.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Jun 15, 2023
1 parent fabe31a commit 79e943f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sdk/notificationhubs/notification-hubs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 1.0.2 (Unreleased)
## 1.0.2 (2023-06-15)

### Features Added

Expand All @@ -10,6 +10,10 @@

- [#25230](ttps://github.com/Azure/azure-sdk-for-js/issues/25230) - Added section for React Native support in troubleshooting.

### Bugs Fixed

- [#25316](https://github.com/Azure/azure-sdk-for-js/issues/25914) - Fix `parseXMLError` to properly handle the XML document response.

## 1.0.1 (2023-03-21)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function serializeToAtomXmlRequest(
export async function parseXMLError(bodyText: string): Promise<string | undefined> {
let result: string | undefined;
const xmlError = await parseXML(bodyText, { includeRoot: true });
const detail = xmlError["Detail"];
const detail = xmlError["Error"]["Detail"];
if (isDefined(detail)) {
return detail;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "@azure/test-utils";
import { parseXMLError } from "../../../src/utils/xmlUtils.js";

const NOTIFICATION_XML_ERROR = `
<Error>
<Code>400</Code>
<Detail>The HTTP header 'ServiceBusNotification-Format' has an invalid value: 'fcmlegacy'. Allowed values are 'windows', 'apple', 'gcm', 'template', 'adm', or 'windowsphone'.</Detail>
</Error>
`;

describe("xmlUtils", () => {
describe("parseXMLError", () => {
it("should parse the error", async () => {
const error = await parseXMLError(NOTIFICATION_XML_ERROR);
assert.equal(
error,
"The HTTP header 'ServiceBusNotification-Format' has an invalid value: 'fcmlegacy'. Allowed values are 'windows', 'apple', 'gcm', 'template', 'adm', or 'windowsphone'."
);
});
});
});

0 comments on commit 79e943f

Please sign in to comment.