Error Object Members
Learn about Error object members in SuiteScript 2.1, including handling error messages and document IDs in machine translation processes.
The Error object in SuiteScript 2.1 provides essential properties for managing errors encountered during the translation process. Understanding these members is crucial for developers working with the N/machineTranslation module.
What Are the Members of the Error Object?
The following table outlines the available members of the Error object, their types, and descriptions:
| Member Name | Type | Description | Supported Script Types |
|---|---|---|---|
Error.documentId | string | The ID of the document in which the error occurred. | Server scripts |
Error.message | string | The error message returned from the translation service. | Server scripts |
Handling Errors in Code
When using the machineTranslation module, it’s important to handle errors gracefully. Below is an illustrative code sample demonstrating how to access error members:
1// Add additional code2...3 4const myDocument = machineTranslation.createDocument({5 id: 'myDoc',6 text: 'This is a document to be translated.'7});8 9const translationResults = machineTranslation.translate({10 documents: [myDocument],11 targetLanguage: machineTranslation.Language.CZECH12});13 14if (translationResults.errors.length) {15 // Handle the error message16 const docErrorId = translationResults.errors[0].documentId;17 const docErrorMessage = translationResults.errors[0].message;18}19 20...21// Add additional codeThis script creates a translation request for a document and checks for any errors that might arise during the process, allowing for effective error management.
Conclusion
Utilizing the Error object members effectively helps to enhance error handling in translation scripts, ensuring smoother operations and better user experience.
Frequently Asked Questions (4)
What properties are available in the Error object in SuiteScript 2.1?
Which script types support Error object members in SuiteScript?
How can I access the document ID and error message from the machineTranslation module?
Do I need special configurations to use the Error object with machineTranslation in SuiteScript 2.1?
Was this article helpful?
More in SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- SuiteScript 2.x Sublist Values: Standard and Dynamic Mode
Use setSublistValue in standard mode; select a line, set its current value and commit it in dynamic mode. Choose the API from the record's mode.
- SuiteScript Record.setValue: Body Fields, Types and Errors
Set NetSuite body fields with Record.setValue, matching field IDs and value types and checking common API errors.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
