提交 93041aad 编写于 作者: D duanweiling

增加首选项错误码文档

Signed-off-by: Nduanweiling <duanweiling@huawei.com>
上级 061300e8
...@@ -58,7 +58,6 @@ try { ...@@ -58,7 +58,6 @@ try {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}) })
} catch (err) { } catch (err) {
...@@ -85,7 +84,6 @@ try { ...@@ -85,7 +84,6 @@ try {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}) })
} catch (err) { } catch (err) {
...@@ -161,7 +159,6 @@ try{ ...@@ -161,7 +159,6 @@ try{
} catch(err) { } catch(err) {
console.log("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.log("Failed to get preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
## data_preferences.deletePreferences ## data_preferences.deletePreferences
...@@ -350,8 +347,9 @@ try { ...@@ -350,8 +347,9 @@ try {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
expect(true).assertEqual(val);
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
...@@ -375,11 +373,13 @@ try { ...@@ -375,11 +373,13 @@ try {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
expect(true).assertEqual(val);
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
## data_preferences.removePreferencesFromCache ## data_preferences.removePreferencesFromCache
...@@ -482,6 +482,7 @@ try { ...@@ -482,6 +482,7 @@ try {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
expect(true).assertEqual(val);
console.info("Succeeded in getting value of 'startup'. val: " + val); console.info("Succeeded in getting value of 'startup'. val: " + val);
}) })
} catch (err) { } catch (err) {
...@@ -555,7 +556,7 @@ try { ...@@ -555,7 +556,7 @@ try {
}) })
} catch (err) { } catch (err) {
console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message); console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
}; }
``` ```
...@@ -578,7 +579,7 @@ getAll(): Promise&lt;Object&gt; ...@@ -578,7 +579,7 @@ getAll(): Promise&lt;Object&gt;
```js ```js
try { try {
let promise = preferences.getAll(); let promise = preferences.getAll();
promise.then((value) => { promise.then((value) => {
let allKeys = Object.keys(value); let allKeys = Object.keys(value);
console.info('getAll keys = ' + allKeys); console.info('getAll keys = ' + allKeys);
console.info("getAll object = " + JSON.stringify(value)); console.info("getAll object = " + JSON.stringify(value));
...@@ -649,7 +650,7 @@ put(key: string, value: ValueType): Promise&lt;void&gt; ...@@ -649,7 +650,7 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
```js ```js
try{ try{
let promise = preferences.put('startup', 'auto'); let promise = preferences.put('startup', 'auto');
promise.then(() => { promise.then(() => {
console.info("Succeeded in putting value of 'startup'."); console.info("Succeeded in putting value of 'startup'.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message); console.info("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message);
...@@ -678,7 +679,7 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -678,7 +679,7 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
try{ try{
preferences.has('startup', function (err, val) { preferences.has('startup', function (err, val) {
if (err) { if (err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
...@@ -719,7 +720,7 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -719,7 +720,7 @@ has(key: string): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```js
try{ try{
let promise = preferences.has('startup'); let promise = preferences.has('startup');
promise.then((val) => { promise.then((val) => {
if (val) { if (val) {
...@@ -730,10 +731,9 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -730,10 +731,9 @@ has(key: string): Promise&lt;boolean&gt;
}).catch((err) => { }).catch((err) => {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -855,7 +855,7 @@ flush(): Promise&lt;void&gt; ...@@ -855,7 +855,7 @@ flush(): Promise&lt;void&gt;
```js ```js
try { try {
let promise = preferences.flush(); let promise = preferences.flush();
promise.then(() => { promise.then(() => {
console.info("Succeeded in flushing."); console.info("Succeeded in flushing.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.info("Failed to flush. code =" + err.code + ", message =" + err.message);
...@@ -970,10 +970,10 @@ try { ...@@ -970,10 +970,10 @@ try {
console.info("Succeeded in flushing."); // observer will be called. console.info("Succeeded in flushing."); // observer will be called.
}) })
}) })
}) })
} catch (error) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.info("Failed to flush. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -996,7 +996,7 @@ off(type: 'change', callback?: Callback&lt;{ key : string }&gt;): void ...@@ -996,7 +996,7 @@ off(type: 'change', callback?: Callback&lt;{ key : string }&gt;): void
```js ```js
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
console.info("Failed to get preferences."); console.info("Failed to get preferences.");
return; return;
...@@ -1021,8 +1021,8 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen ...@@ -1021,8 +1021,8 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
}) })
preferences.off('change', observer); preferences.off('change', observer);
}) })
}) })
} catch (error) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message);} console.info("Failed to flush. code =" + err.code + ", message =" + err.message);}
``` ```
......
...@@ -8,7 +8,9 @@ Failed to delete preferences. ...@@ -8,7 +8,9 @@ Failed to delete preferences.
删除首选项失败。 删除首选项失败。
**可能原因**<br> **可能原因**<br>
系统错误导致文件删除失败。 系统错误导致文件删除失败,可能原因如下:
1. 要删除的文件不存在。
2. 没有操作权限。
**处理步骤**<br> **处理步骤**<br>
重启设备后再次尝试。 重启设备后再次尝试。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册