Skip to content

Instantly share code, notes, and snippets.

@jiju-MS
Last active November 12, 2019 06:10
Show Gist options
  • Save jiju-MS/3756f673d131f339f4d810793b9236f8 to your computer and use it in GitHub Desktop.
Save jiju-MS/3756f673d131f339f4d810793b9236f8 to your computer and use it in GitHub Desktop.
name: Return Error
description: ''
host: EXCEL
api_set: {}
script:
content: |-
/**
* Calculates the volume of a sphere.
* @customfunction
* @param {any} res
* @returns The volume of the sphere.
*/
function TestErrorArray(res: any):any[][] {
var error;
if (res == 1) {
error =
{
"errorcode": CustomFunctions.ErrorCode.notAvailable,
"errormessage": "test"
};
console.log("common case")
return [[1],[2],[error]];
}
if (res == 2) {
var error1 =
{
"errorcode": CustomFunctions.ErrorCode.notAvailable,
"errormessage": "test"
};
var error2 =
{
"errorcode": CustomFunctions.ErrorCode.invalidValue,
"errormessage": "test"
};
var error3 =
{
"errorcode": CustomFunctions.ErrorCode.divisionByZero,
"errormessage": "test"
};
console.log("common case")
return [[error1], [error2], [error3]];
}
}
/**
* Calculates the volume of a sphere.
* @customfunction
* @param {any} res
* @returns The volume of the sphere.
*/
function TestError(res:any) {
var error;
if (res == 1) {
error =
{
"errorcode": CustomFunctions.ErrorCode.notAvailable,
"errormessage": "test"
};
console.log("common case")
return error;
}
if (res == 2) {
error =
{
"errorcode": "#N/A",
"errormessage": "test"
};
console.log("using string as errorcode")
return error;
}
if (res == 3) {
error =
{
"errorcode": CustomFunctions.ErrorCode.notAvailable,
"errormessage": ""
};
console.log("error message is empty")
return error;
}
if (res == 4) {
error =
{
"errorcode": CustomFunctions.ErrorCode.notAvailable
};
console.log("no error message")
return error;
}
if (res == -1) {
error =
{
"errorcode": "#BUSY",
"errormessage": "test"
};
console.log("errorcode = #BUSY")
return error;
}
if (res == -2) {
error =
{
"errorcode": 42,
"errormessage": "test"
};
console.log("errorcode = 42")
return error;
}
if (res == -3) {
error =
{
"errorcode": "#N/A!",
"errormessage": "test"
};
console.log("errorcode = 42")
return error;
}
}
language: typescript
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
core-js@2.4.1/client/core.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment