Skip to content

Commit a813ece

Browse files
author
Linsen Wu
committed
Addressed Jorge's comments
1 parent 4371b09 commit a813ece

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

Diff for: src/components/notebookRenderStrategy.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { NotebookOpenedIconSvg } from './icons/notebookOpenedIcon.svg';
1212
import { NotebookClosedIconSvg } from './icons/notebookClosedIcon.svg';
1313
import { ChevronSvg } from './icons/chevron.svg';
1414
import { CreateNewSectionNode } from './createNewSection/createNewSectionNode';
15-
import * as OneNoteApi from 'onenoteapi';
1615
import { SpinnerIconSvg } from './icons/spinnerIcon.svg';
1716
import { Strings } from '../strings';
1817

@@ -46,8 +45,8 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
4645
}
4746

4847
getChildren(childrenLevel: number): JSX.Element[] {
49-
if (typeof (this.notebook.apiHttpErrorCode) === 'number') {
50-
const errorString = Strings.getError(this.notebook.apiHttpErrorCode);
48+
if (this.notebook.apiHttpErrorMessage) {
49+
const errorString = this.notebook.apiHttpErrorMessage;
5150
return [
5251
<li role='status' aria-live='polite' aria-label={errorString} className='progress-row'>
5352
<div>{errorString}</div>
@@ -144,15 +143,19 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
144143
}
145144

146145
private onExpand() {
147-
if (this.notebook.needsToFetchChildren && this.notebook.apiUrl && this.globals.oneNoteDataProvider && !!this.globals.callbacks.onNotebookInfoReturned) {
146+
if (this.notebook.needsToFetchChildren && this.notebook.apiUrl && this.globals.oneNoteDataProvider) {
148147
this.globals.oneNoteDataProvider.getNotebookBySelfUrl(this.notebook.apiUrl, 5).then((notebook) => {
149148
this.notebook.sections = notebook.sections
150149
this.notebook.sectionGroups = notebook.sectionGroups
151-
}).catch((apiError: OneNoteApi.RequestError) => {
152-
this.notebook.apiHttpErrorCode = apiError.statusCode;
150+
}).catch((apiError: any) => {
151+
try {
152+
this.notebook.apiHttpErrorMessage = JSON.parse(apiError.response).error.message
153+
} catch (error) {
154+
this.notebook.apiHttpErrorMessage = Strings.getError(apiError.statusCode);
155+
}
153156
}).then(() => {
154157
this.notebook.needsToFetchChildren = false;
155-
if (!!this.globals.callbacks.onNotebookInfoReturned) {
158+
if (this.globals.callbacks.onNotebookInfoReturned) {
156159
this.globals.callbacks.onNotebookInfoReturned(this.notebook);
157160
}
158161
})

Diff for: src/components/sharedNotebookRenderStrategy.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { NotebookClosedIconSvg } from './icons/notebookClosedIcon.svg';
1515
import { SpinnerIconSvg } from './icons/spinnerIcon.svg';
1616
import { ChevronSvg } from './icons/chevron.svg';
1717
import { CreateNewSectionNode } from './createNewSection/createNewSectionNode';
18-
import * as OneNoteApi from 'onenoteapi';
1918

2019
export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrategy {
2120
onClickBinded = () => {};
@@ -52,8 +51,8 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
5251
}
5352

5453
getChildren(childrenLevel: number): JSX.Element[] {
55-
if (typeof (this.notebook.apiHttpErrorCode) === 'number') {
56-
const errorString = Strings.getError(this.notebook.apiHttpErrorCode);
54+
if (this.notebook.apiHttpErrorMessage) {
55+
const errorString = this.notebook.apiHttpErrorMessage;
5756
return [
5857
<li role='status' aria-live='polite' aria-label={errorString} className='progress-row'>
5958
<div>{errorString}</div>
@@ -155,7 +154,7 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
155154

156155
this.globals.oneNoteDataProvider.getSpNotebookProperties(this.notebook, depth, true).then((apiProperties) => {
157156
if (!apiProperties) {
158-
this.notebook.apiHttpErrorCode = 404;
157+
this.notebook.apiHttpErrorMessage = Strings.getError(404);
159158
return;
160159
}
161160

@@ -164,8 +163,12 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
164163
if (this.globals.notebookListUpdater) {
165164
this.globals.notebookListUpdater.updateNotebookList([this.notebook]);
166165
}
167-
}).catch((apiError: OneNoteApi.RequestError) => {
168-
this.notebook.apiHttpErrorCode = apiError.statusCode;
166+
}).catch((apiError: any) => {
167+
try {
168+
this.notebook.apiHttpErrorMessage = JSON.parse(apiError.response).error.message
169+
} catch (error) {
170+
this.notebook.apiHttpErrorMessage = Strings.getError(apiError.statusCode);
171+
}
169172
}).then(() => {
170173
const { onSharedNotebookInfoReturned } = this.globals.callbacks;
171174
if (!!onSharedNotebookInfoReturned) {

Diff for: src/oneNoteDataStructures/notebook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SectionGroup } from './sectionGroup';
44

55
export interface Notebook extends OneNoteItem {
66
// Properties that need to be loaded-on-demand
7-
apiHttpErrorCode?: number;
7+
apiHttpErrorMessage?: string;
88

99
expanded: boolean;
1010
sectionGroups: SectionGroup[];

0 commit comments

Comments
 (0)