Skip to content

How to catch API errors ? #154

@j4kim

Description

@j4kim

Your environment

  • Version used: (master branch)
  • Platform used: JavaScript
  • Rendering engine used: SVG
  • Browser Name and Version: Chrome 59.0.3071.115 (Build officiel) (64 bits)
  • Operating System and version (desktop or mobile): Windows 10

Expected Results

I have a file input for entering a guitar pro file. I load the file in alphaTab when the input changes. In order to validate the file, I need to catch the potential import errors from AlphaTab.

The API could trigger the "alphaTab.error" event when an error occurs. Something like this:

at.on('alphaTab.error', function (e, data) {
    if(data.msg === "importError") ...
}

Observed Results

The errors seem to be just printed in the console.

Steps to Reproduce (for bugs)

Load a non valid file and try to be notified by some error.

Possible Solution

Here is what I did: j4kim@54ddd85
Added manually a throw statement on the failure callback of the fileLoader methods. It does the job in most cases but there are inconveniences:

  • I have to maintain an other version up to date, which I found out today is not easy
  • It doesn't even catch all the import errors, some files pass through this trick (text files mostly). I think I am not throwing errors in all cases...

well, it's not a good solution.

Metadata

Metadata

Assignees

Labels

area-documentationRelated to documentation and sample codestate-acceptedThis is a valid topic to work on.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions