Last active
September 22, 2015 10:05
-
-
Save barmatz/86ab2687c00cb62dc5d5 to your computer and use it in GitHub Desktop.
JavaScript error parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function errorParser(err) { | |
| if (err) { | |
| if (typeof err === 'function') { | |
| err = err(); | |
| } | |
| if (typeof err === 'object') { | |
| if ('responseText' in err) { | |
| err = err.responseText; | |
| try { | |
| err = JSON.parse(err); | |
| } catch (e) { | |
| } finally { | |
| return this.parseError(err); | |
| } | |
| } else if ('message' in err) { | |
| return err.message; | |
| } else if ('error' in err) { | |
| return this.parseError(err.error); | |
| } | |
| } | |
| if (typeof err !== 'string') { | |
| err = err.toString(); | |
| } | |
| try { | |
| err = Ember.$(new DOMParser().parseFromString(err, 'text/xml')).find('parsererror > div').html(); | |
| } catch (e) {} | |
| return err; | |
| } else { | |
| return 'Unknown error'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment