Community discussions

MikroTik App
 
GeraldSB
just joined
Topic Author
Posts: 7
Joined: Fri May 09, 2014 6:32 pm

How to retrieve error details inside the on-error clause

Sat Apr 18, 2020 4:17 am

When using the on-error clause for a /tool fetch command (or other) is it possible to get the actual error message or number ?

There must be some info available because when failing in the terminal there usually is a message saying what went wrong.
For example:
[admin@router] > /tool fetch url=htt://bad.protocol.com
failure: invalid URL protocol

The question is how can I get this message inside the on-error clause.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to retrieve error details inside the on-error clause

Sat Apr 18, 2020 3:56 pm

As far as I have seen you can use on-error for two things.
1. Prevent script from stop running if there are one or more error.
2. Run an alternate code if some error occurs.

I have not seen any possibility to get the actual error listed.
That would be nice to have, so if MT reads this, please add.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to retrieve error details inside the on-error clause

Thu Sep 09, 2021 6:12 pm

THE CORRECT WAY IS SANITIZE THE STRING FIRST...

for example:
:if ($theurlstring~"^(http|https|ftp|sftp|tftp)://") do={
    # something
} else={
    # do nothing
}

then you can use this example to intercept fetch errors:
viewtopic.php?f=2&t=178355#p878634
 
GeraldSB
just joined
Topic Author
Posts: 7
Joined: Fri May 09, 2014 6:32 pm

Re: How to retrieve error details inside the on-error clause

Sat Dec 04, 2021 12:37 pm

THE CORRECT WAY IS SANITIZE THE STRING FIRST...
for example:
:if ($theurlstring~"^(http|https|ftp|sftp|tftp)://") do={
    # something
} else={
    # do nothing
}
then you can use this example to intercept fetch errors:
viewtopic.php?f=2&t=178355#p878634

The question is about getting the on-error detailed info.
The bad URL is just an example that generates an error.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: How to retrieve error details inside the on-error clause

Wed Dec 08, 2021 12:15 pm

As far as I know this is not possible.
MikroTik knows about this and they consider implementing, but that has not yet happened.

Who is online

Users browsing this forum: No registered users and 58 guests