Modify ↓
Opened 19 years ago
Closed 19 years ago
#126 closed defect (fixed)
If the OSM api returns the error message details, display those to the user
| Reported by: | anonymous | Owned by: | imi |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | Core | Version: | latest |
| Keywords: | Cc: |
Description
There's now code in the OSM api (0.3 and rails 0.4) so that calls to /api/0.x/map will return a detailed help message, along with their status code 400. This should be live shortly.
We therefore want JOSM to notice when it gets a detailed error message, and display that to the user instead of just saying 400 bad request.
It's quite easy to support this, patch attached.
Attachments (0)
Change History (2)
follow-up: 2 comment:1 by , 19 years ago
comment:2 by , 19 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Trac's giving an error when trying to attach tickets :(
Index: src/org/openstreetmap/josm/io/ProgressInputStream.java
===================================================================
--- src/org/openstreetmap/josm/io/ProgressInputStream.java (revision 215)
+++ src/org/openstreetmap/josm/io/ProgressInputStream.java (working copy)
@@ -18,9 +18,22 @@
private final URLConnection connection;
private PleaseWaitDialog pleaseWaitDlg;
- public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException {
+ public class OSMServerException extends IOException {
+ OSMServerException(String e) { super(e); }
+ }
+
+ public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException, OSMServerException {
this.connection = con;
- this.in = con.getInputStream();
+
+ try {
+ this.in = con.getInputStream();
+ } catch(IOException e) {
+ if(con.getHeaderField("Error") != null) {
+ throw new OSMServerException(con.getHeaderField("Error"));
+ }
+ throw e;
+ }
+
int contentLength = con.getContentLength();
this.pleaseWaitDlg = pleaseWaitDlg;
if (pleaseWaitDlg == null)
Index: src/org/openstreetmap/josm/io/OsmServerWriter.java
===================================================================
--- src/org/openstreetmap/josm/io/OsmServerWriter.java (revision 215)
+++ src/org/openstreetmap/josm/io/OsmServerWriter.java (working copy)
@@ -182,6 +182,12 @@
if (retCode == 410 && requestMethod.equals("DELETE"))
return; // everything fine.. was already deleted.
if (retCode != 200) {
+ // Look for a detailed error message from the server
+ if(activeConnection.getHeaderField("Error") != null) {
+ retMsg += "\n" + activeConnection.getHeaderField("Error");
+ }
+
+ // Report our error
ByteArrayOutputStream o = new ByteArrayOutputStream();
OsmWriter.output(o, new OsmWriter.Single(osm, true));
System.out.println(new String(o.toByteArray(), "UTF-8").toString());
Note:
See TracTickets
for help on using tickets.



Trac's giving an error when trying to attach tickets :(
Index: src/org/openstreetmap/josm/io/ProgressInputStream.java
===================================================================
--- src/org/openstreetmap/josm/io/ProgressInputStream.java (revision 215)
+++ src/org/openstreetmap/josm/io/ProgressInputStream.java (working copy)
@@ -18,9 +18,22 @@
+ public class OSMServerException extends IOException {
+ OSMServerException(String e) { super(e); }
+ }
+
+ public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException, OSMServerException {
+
+ try {
+ this.in = con.getInputStream();
+ } catch(IOException e) {
+ if(con.getHeaderField("Error") != null) {
+ throw new OSMServerException(con.getHeaderField("Error"));
+ }
+ throw e;
+ }
+
Index: src/org/openstreetmap/josm/io/OsmServerWriter.java
===================================================================
--- src/org/openstreetmap/josm/io/OsmServerWriter.java (revision 215)
+++ src/org/openstreetmap/josm/io/OsmServerWriter.java (working copy)
@@ -182,6 +182,12 @@
+ Look for a detailed error message from the server
+ if(activeConnection.getHeaderField("Error") != null) {
+ retMsg += "\n" + activeConnection.getHeaderField("Error");
+ }
+
+ Report our error